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

 
Participant
3 weeks, 6 days ago.

  • Author
    Posts
  • #112603

    Participant
    Points: 0
    Rank: Member

    How to list directories and sort by size

  • #112627

    Participant
    Points: 0
    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 @{
    name=$fso.getFolder($folder.fullname.tostring()).path;
    size=[int]($fso.GetFolder($folder.FullName.ToString()).size /1MB)}
    }
    
    $folders | sort size -Descending | ? size -gt 1000
    
    • #112675

      Participant
      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,

       

You must be logged in to reply to this topic.