List of directories by size

Welcome Forums General PowerShell Q&A List of directories by size

This topic contains 2 replies, has 2 voices, and was last updated by

3 months, 3 weeks ago.

  • Author
  • #112603

    Points: 0
    Rank: Member

    How to list directories and sort by size

  • #112627

    Points: 15
    Rank: Member

    Hello, Hitesh.

    You should be able to get what you want using the script bellow:

    #requires -version 3.0
    $path = "c:\"
    $fso = New-Object -ComObject scripting.filesystemobject
    $folders = Foreach($folder in (Get-ChildItem $path -Directory -Recurse))
    New-Object -TypeName psobject -Property @{
    size=[int]($fso.GetFolder($folder.FullName.ToString()).size /1MB)}
    $folders | sort size -Descending | ? size -gt 1000
    • #112675

      Points: 0
      Rank: Member

      Hi Renan,

      great, thank you. does exactly what I was looking for to.

      I did basic powershell and this is what I came up to and has some flaws, but the one you gave is perfect

      gci * | where mode -eq "d—–" | % {$_.Name; gci -recurse $_.Name | Measure-object -Sum length| % {$_.sum/1024/1024} | ft $_.Name,Sum; " "}

      Thank you,


The topic ‘List of directories by size’ is closed to new replies.