« Powershell Find VM with snapshotsView Virtual Center Sessions »

Retrieve directory size with Powershell

06/10/11

Retrieve directory size with Powershell

Permalink 12:29:00 pm by admin, Categories: Personal

Just a little script to get sizes (in Mb) of directories, in this case the size of the user's home folders.

 

$directories = Get-ChildItem \\domain.local\dfs\home | Where {$_.psIsContainer -eq $true}
foreach ($directory in $directories) {
$colItems = (Get-ChildItem \\domain.local\dfs\Home\$directory -Recurse | Measure-Object -property length -sum)
$directory.Name + ":"
"{0:N2}" -f ($colItems.sum / 1MB) + " MB"
}