Solved

Need assistance with powershell report

Posted on 2010-09-18
4
1,266 Views
Last Modified: 2012-06-27
Please help as I am a newbie and pulling my hair out. What I am trying to accomplish is the report to display like the example below. I need a script that will display the total size of files owned by a user. Something like this below.

User      Total size
Userx      500mb
userT      1GB
Usera          40KB


What I have come up thus far is this.

$total_count
Get-childitem -recurse \\servername\share | foreach-object { $total_count += $_.Length }
$total_count

This produces the total size of the files but here is another issue. You see Get-acl gets the owner
of the file which is great. I just cannot seem to pipe these commands together to get this information. Get-childitem from what I can tell does not have the capability to get the file owner unless I am wrong.

I am also hoping to specify if its kb based on the size, then mb based on a size and then GB. This is purely cosmetic and not really that important. I am just having trouble getting the above to show.
0
Comment
Question by:tdodd72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
Blake_1 earned 250 total points
ID: 33710547
$hashTotal = @{}
Get-ChildItem -Recurse \\server\share | foreach {
    $objOwner = (Get-ACL $_.FullName).Owner
    $hashTotal[$objOwner] += $_.Length
}
$hashTotal
0
 

Author Comment

by:tdodd72
ID: 33710846
FYI: After running this script I keep getting this error below and the script just looks at me while it hangs.


Index operation failed; the array index evaluated to null.
At line:3 char:16
+     $hashTotal[ <<<< $objOwner] += $_.Length
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:3 char:16
+     $hashTotal[ <<<< $objOwner] += $_.Length
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:3 char:16
+     $hashTotal[ <<<< $objOwner] += $_.Length
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:3 char:16
+     $hashTotal[ <<<< $objOwner] += $_.Length
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:3 char:16
+     $hashTotal[ <<<< $objOwner] += $_.Length
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:3 char:16
+     $hashTotal[ <<<< $objOwner] += $_.Length
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:3 char:16
+     $hashTotal[ <<<< $objOwner] += $_.Length
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:3 char:16
+     $hashTotal[ <<<< $objOwner] += $_.Length
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:3 char:16
+     $hashTotal[ <<<< $objOwner] += $_.Length
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
0
 
LVL 5

Expert Comment

by:Blake_1
ID: 33710872
Are you using Powershell 2.0?  If you're not sure, it is reported if you type 'Get-Host'.  (NB v2 is also in a folder underneath 'v1.0')
0
 

Author Closing Comment

by:tdodd72
ID: 33712121
I found the issue and thank you sir for your help. My permissions were not propogated down the fileshare properly. Thanks a million for your help. The script ran and it looks sweet.
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question