get_folder_size.ps1

 function filesize ([string]$filepath)
{
    if ($filepath -eq $null)
    {
        throw "路径不能为空"
    }
    $hash_size=@{} 
    dir -Path $filepath |
    ForEach-Object -Process {
        if ($_.psiscontainer -eq $true)
        {
            $length = 0
            dir -Path $_.fullname -Recurse | ForEach-Object{
                $length += $_.Length
            }
            $l = $length/1MB
            [int]$FolderSIZE=" {0:n1}" -f $l
            $hash_size.($_.name)=$FolderSIZE
        }
    }
    $hash_size.GetEnumerator() | Sort-Object Value 
}
filesize -filepath ".\"

 

posted on 2017-06-08 22:04  cm20121009  阅读(153)  评论(0编辑  收藏  举报