List of directories by size

How to list directories and sort by size

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
<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>

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,