Audit My Documents Size on Local machines to plan for Folder Redirecttion

ncomper
ncomper used Ask the Experts™
on
Hi All

We are planning to redirect our users My Documents to a file server, however prior to doing this i would like to know how much data we are going to end up with, is there a script that can go out to each PC and report back the size of the my documents folder, 95% of our estate is Windows 7 so  mostly concerned with this O/S,

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Check out this article. The guy has the same question.
http://forums.petri.com/showthread.php?t=43178
Top Expert 2014

Commented:
I haven't tested except on a local machine, but should work.
Using PS Remoting...
$computers = Get-Content computerlist.txt
$scriptblock = {
    Get-ChildItem c:\users | Get-ChildItem -filter "documents" |
     Get-ChildItem -Recurse -force -ea SilentlyContinue |
     Where { !($_.PsIsContainer) } |
     Select -expand length |
     Measure-Object -Sum |
     Select sum
}
Invoke-Command -ComputerName $computers -ScriptBlock $scriptblock | Export-CSV DocumentsSize.csv -notype

Open in new window

Author

Commented:
Thanks, does anything need to be enabled on the remote client machine, it runs on mine OK but not remote PC's (firewall etc is off)

Also is it possible to get the path in export so we know the user?

Thanks
Top Expert 2014
Commented:
Yes, PS Remoting needs to be enabled on all the target machines.
http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/24/an-introduction-to-powershell-remoting-part-two-configuring-powershell-remoting.aspx
This will be much faster than using UNC paths.

If you're only concerned with the total amount of space required then I wouldn't think you'd be as concerned about each user.  I was also thinking that you probably only have one main user for each machine, however, perhaps that isn't the case.
Here's a revised script with the path included.
$computers = Get-Content complist.txt
$scriptblock = {
    Get-ChildItem c:\users | Get-ChildItem -filter "documents" | ForEach `
    {
         $path = $_.FullName
         Get-ChildItem $path -Recurse -force -ea SilentlyContinue |
         Where { !($_.PsIsContainer) } |
         Select -expand length |
         Measure-Object -Sum |
         Select @{n="Size";e={$_.sum}},@{n="Path";e={$path}}
    }
}
Invoke-Command -ComputerName $computers -ScriptBlock $scriptblock |
 Select PsComputerName,Size,Path |
 Export-CSV DocumentsSize.csv -notype

Open in new window


BTW, the .CSV generated is really just a data store for the information gathered.  It's still necessary to do your analysis to get the aggregate data you want according to your needs and tools available.  Here's an example of just summing all the sizes together with a little formatting.
$totalsize = Import-CSV DocumentsSize.csv |
 Select -expand Size |
 Measure-Object -Sum
"Total size: {0:N2} MB" -f ($totalsize.sum / 1MB)

Open in new window

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial