Can you tell a PS novice how to get this to sort by size? That would make it 
perfect.


John

From: Michael B. Smith [mailto:[email protected]]
Sent: Thursday, November 10, 2011 1:41 PM
To: NT System Admin Issues
Subject: RE: Easy Way to View and Sort By Folder Sizes

I wrote this for someone here (well, on some mailing list, I think it was this 
one) a couple months ago, but I use it all the time now.

-----get-foldersize.ps1-----
function Get-FolderSize( $path = $home )
{
   $code = { ('{0:0.0} MB' -f ($this/1MB)) }
   Get-ChildItem -Path $Path |
      Where-Object { $_.Length -eq $null } |
      ForEach-Object {
           Write-Progress -Activity 'Calculating Total Size for:' -Status 
$_.FullName
       $sum = Get-ChildItem $_.FullName -Recurse -ErrorAction SilentlyContinue |
        Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue
      $bytes = $sum.Sum
      if ($bytes -eq $null) { $bytes = 0   }
      $result = 1 | Select-Object -Property Path, TotalSize
      $result.Path = $_.FullName
      $result.TotalSize = $bytes |
        Add-Member -MemberType ScriptMethod -Name toString -Value $code -Force 
-PassThru
      $result
    }
}

Get-FolderSize $args
-----get-foldersize.ps1-----

Example:

PS C:\Scripts> .\Get-FolderSize.ps1 c:\windows

Path                                                                  TotalSize
----                                                                  ---------
C:\windows\ADAM                                                          3.6 MB
C:\windows\ADWS                                                          0.7 MB
C:\windows\AppCompat                                                     0.1 MB
C:\windows\AppPatch                                                     10.4 MB
C:\windows\assembly                                                   2436.4 MB
C:\windows\Boot                                                         19.7 MB
C:\windows\Branding                                                      2.2 MB
C:\windows\CSC                                                           0.0 MB
C:\windows\Cursors                                                       0.1 MB
C:\windows\debug                                                         8.6 MB
C:\windows\diagnostics                                                   1.0 MB
C:\windows\DigitalLocker                                                 0.0 MB
C:\windows\Downloaded Installations                                      4.9 MB
C:\windows\Downloaded Program Files                                     19.7 MB
C:\windows\Driver Cache                                                  0.3 MB
C:\windows\en                                                            0.1 MB
C:\windows\en-US                                                         0.1 MB
C:\windows\Fonts                                                       376.1 MB
C:\windows\Globalization                                                 9.6 MB
C:\windows\Help                                                         68.1 MB
C:\windows\idmu                                                          0.3 MB
C:\windows\IME                                                         136.8 MB
......

Regards,

Michael B. Smith
Consultant and Exchange MVP
http://TheEssentialExchange.com

From: John Hornbuckle 
[mailto:[email protected]]<mailto:[mailto:[email protected]]>
Sent: Thursday, November 10, 2011 10:42 AM
To: NT System Admin Issues
Subject: Easy Way to View and Sort By Folder Sizes

We use folder redirection here, and I'm trying to get a handle on which users 
have the most stuff.

So we have something like:

x:\path\user1
x:\path\user2
x:\path\user3

and so on.

I'd like to look at x:\path and sort all the folders in it by size, displaying 
the size in MB. So the results would be something like:

x:\path\user3    500 MB
x:\path\user1    200 MB
x:\path\user2    100 MB

What's the easiest way to do this?

I'll need specifics (e.g., don't tell me I can do it with PS unless you're 
gonna tell me precisely how).

:)



John Hornbuckle, MSMIS, PMP
MIS Department
Taylor County School District
www.taylor.k12.fl.us



~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

Reply via email to