Solved

Need assistance with powershell report

Posted on 2010-09-18
4
1,220 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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