• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1429
  • Last Modified:

Need assistance with powershell report

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
tdodd72
Asked:
tdodd72
  • 2
  • 2
1 Solution
 
Blake_1Commented:
$hashTotal = @{}
Get-ChildItem -Recurse \\server\share | foreach {
    $objOwner = (Get-ACL $_.FullName).Owner
    $hashTotal[$objOwner] += $_.Length
}
$hashTotal
0
 
tdodd72Author Commented:
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
 
Blake_1Commented:
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
 
tdodd72Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now