function Get-Size($dir=".")
{
$ds = get-item $dir | % { $f = $_; get-childitem -r $_.FullName | measure-object -property length -sum -ErrorAction SilentlyContinue | select @{Name="Name";Expression={$f}},Sum}
$ds | foreach-object { if ( $_.Sum -le 999KB) {$_.Sum = ([string]::Format("{0:#.##}",($_.Sum)/1KB)) + " KB" ; $_ } elseif ( $_.Sum -le 999MB) {$_.Sum = ([string]::Format("{0:#.##}",($_.Sum)/1MB)) + " MB" ; $_ } elseif ( $_.Sum -le 999GB) {$_.Sum = ([string]::Format("{0:#.##}",($_.Sum)/1GB)) + " GB" ; $_ }}
} # End Get-Size
# set Alias of 'du' for Get-Size
Set-Alias du Get-Size
Get-Size D:\IT\* > C:\Powershellscripts\Directorysize\itfoldersize.txt
|