function Show-SpaceUsage
{
[CmdLetBinding()]
param(
[Parameter(Mandatory=$true, Position=0)]
[ValidateScript({Test-Path $_ })]
[string]$path,
[decimal]$parentSize=0,
[ValidateNotNullOrEmpty()]
[string]$format = "N2"
)
$size = (Get-ChildItem $path -Recurse | ?{$_.PSIsContainer -eq $false} | measure -property length -sum).sum
$parentPercentage =1
if($parentSize -ne 0)
{
$parentPercentage = $size / $parentSize
}
$item = gi $path
new-object PSObject |
Add-Member -PassThru -MemberType NoteProperty -Name Path -Value $item.FullName |
Add-Member -PassThru -MemberType NoteProperty -Name Name -Value $item.Name |
Add-Member -PassThru -MemberType NoteProperty -Name GB -Value ("{0:$format}" -f ($size / 1GB)) |
Add-Member -PassThru -MemberType NoteProperty -Name MB -Value ("{0:$format}" -f ($size / 1MB)) |
Add-Member -PassThru -MemberType NoteProperty -Name KB -Value ("{0:$format}" -f ($size / 1KB)) |
Add-Member -PassThru -MemberType NoteProperty -Name "Percentage of Parent" -Value ("{0:$format}" -f $parentPercentage)
$dirs = Get-ChildItem $path | ?{$_.PSIsContainer -eq $True} | sort Name
$dirs | %{
Show-SpaceUsage -path $_.FullName -parentSize $size
Write-verbose ""
}
}
Wyniki są sformatowane do tabeli:
Show-SpaceUsage -path "." -Verbose | Format-Table
Oczywiście można wyniki wyeksportować do csv i tam już posortować po największych folderach:
Show-SpaceUsage -path "." | Export-Csv -path "result.csv" -Delimiter ';' -NoTypeInformation -Encoding ASCII
Brak komentarzy:
Prześlij komentarz