Howtos / Articles

Display Total Folder Size with PowerShell and Sort by Size

The PowerShell command below can be used to display a list containing the total size (in MB) of all the files and folders (recursively) in the current directory, and sort them by total size.

ls -Force | Add-Member -Force -Passthru -Type ScriptProperty -Name Length -Value {ls $this -Recurse -Force | Measure -Sum Length | Select -Expand Sum } | Sort-Object Length -Descending | Format-Table @{label="TotalSize (MB)";expression={[Math]::Truncate($_.Length / 1MB)};width=14}, @{label="Mode";expression={$_.Mode};width=8}, Name

Sample Output:

TotalSize (MB) Mode     Name
-------------- ----     ----
         26499 d----    Windows
         18409 d----    restore
          8189 -a-hs    pagefile.sys
          7989 d-r--    Users
          7672 d-r--    Program Files (x86)
          6141 -a-hs    hiberfil.sys
          2160 d-r--    Program Files
           235 d----    eclipse
           204 d----    NVIDIA
            66 d--h-    ProgramData
            37 d----    PHP
             0 d--hs    $Recycle.Bin
               d--hs    Recovery
               d--hs    System Volume Information
               d----    PerfLogs
               d--hs    Documents and Settings

This may take awhile to run if you run it from a folder with a lot of sub folders/files.



Share this howto article!
  • Facebook
  • Twitter
  • Reddit
  • email

1 comment to Display Total Folder Size with PowerShell and Sort by Size

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>