Solved

Need assistance with powershell report

Posted on 2010-09-18
4
1,176 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
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

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

Author Comment

by:tdodd72
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Synchronize a new Active Directory domain with an existing Office 365 tenant
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now