BOOKING

2018年9月19日星期三

How to calculate the Folder size (script)

how to calculate the folder size and list down all path size.
function filesize ([string]$filepath)
{

if ($filepath -eq $null)
{
throw "can NOT be empty"
}
dir -Path $filepath |
ForEach-Object -Process {
if ($_.psiscontainer -eq $true)
{
$length = 0
dir -Path $_.fullname -Recurse | ForEach-Object{
$length += $_.Length
}
$l = $length/1KB
$_.name + "folder size is: {0:n1} KB" -f $l
}
}

}
filesize -filepath "Z:\Accounts"

没有评论:

发表评论