54 lines
2.2 KiB
PowerShell
54 lines
2.2 KiB
PowerShell
param([ValidateSet('KB','GB','TB')]$SizeUnitName = 'GB',[switch]$NoFilter,[switch]$PassThru)
|
|
$local:zpool_cmd = $null
|
|
$local:excludeType = ''
|
|
|
|
$script:SizeUnit = Invoke-Expression "1$SizeUnitName"
|
|
$script:SizeRound = 2
|
|
$SizeUnit /= 1KB
|
|
|
|
function NewDataRow{param($Size,$Used,$Available,$Percent,$Source,$FSType,$Target)
|
|
[PSCustomObject]@{
|
|
"Size$SizeUnitName" = [Math]::Round($Size /$SizeUnit, $SizeRound)
|
|
"Used$SizeUnitName" = [Math]::Round($Used /$SizeUnit, $SizeRound)
|
|
"Available$SizeUnitName" = [Math]::Round($Available/$SizeUnit, $SizeRound)
|
|
'Used%' = [int]($Percent -replace '%$','')
|
|
Source = $Source
|
|
FSType = $FSType
|
|
Target = $Target
|
|
SourceLevel = $(if($Source[0] -eq '/') { 1 } else {0}) + $Source.Split('/').Count - 1
|
|
TargetLevel = $(if($Target[0] -eq '/') { 1 } else {0}) + $Target.Split('/').Count - 1
|
|
Group = $(switch( $FSType ) { 'zfs' { "$FSType`:$($Source.Split('/')[0])" } 'cifs' { "$FSType`:$($Source.Split('/')[2])" } default { $Source }} )
|
|
}
|
|
}
|
|
|
|
Set-Alias Out-Default Format-Table
|
|
if( $PassThru ) {
|
|
Get-Item alias:/Out-Default | Remove-Item
|
|
}
|
|
|
|
$local:filterParam = [ordered]@{}
|
|
if( -not $NoFilter ) { $filterParam.First = 1 }
|
|
$local:df = @()
|
|
|
|
$(
|
|
& df '--output=size,used,avail,pcent,source,fstype,target' |
|
|
Select-Object -Skip 1 | ForEach-Object {
|
|
$local:df = $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries)
|
|
NewDataRow $df[0] $df[1] $df[2] $df[3] $df[4] $df[5] $df[6]
|
|
} |
|
|
Sort-Object -Property FSType,Target |
|
|
Group-Object -Property FSType |
|
|
ForEach-Object {
|
|
if( $_.Name -eq 'zfs' ) {
|
|
$_.Group |
|
|
Group-Object -Property Group |
|
|
ForEach-Object {
|
|
$_.Group | Sort-Object -Property Source | Select-Object @filterParam
|
|
}
|
|
}
|
|
else { $_.Group }
|
|
} |
|
|
Select-Object -Property "Size$SizeUnitName","Used$SizeUnitName","Available$SizeUnitName",'Used%',Source,FSType,Target
|
|
) |
|
|
Out-Default
|