リモートPCの容量確認

書式がずれては Format コマンドの意味がないような・・・
色々頑張ってみましたが、数値の右詰とか無理そうなので諦めよう。。

■コード

filter GetDiskSize {
    $server_name = $_
    Get-WmiObject -Class win32_logicaldisk -ComputerName $_ |
#        ? { $_.DeviceID -eq "C:" -or $_.DeviceID -eq "D:" } |
        select -Property DeviceID, Size, FreeSpace, `
            @{Name = "ServerName"; Expression = { $server_name }}
}

#文字列配列でサーバ名を列挙し、列挙したサーバ名全部の容量を出力する
("192.168.0.1") |
    GetDiskSize |
    Format-Table -Wrap -Property `
            @{Name = "サーバ"; Expression = { $_.ServerName }; Width=15 } `
            , @{Name = "ドライブレター"; Expression = { $_.DeviceID }; Width=16 } `
            , @{Name = "容量"; Expression = { ("{0:0.00}GB" -F ($_.Size / 1GB)) }; Alignment="Right"; Width=9 } `
            , @{Name = "使用量"; Expression = { ("{0:0.00}GB" -F (($_.Size - $_.FreeSpace) / 1GB)) }; Alignment="Right"; Width=9 } `
            , @{Name = "空き容量(GB)"; Expression = { ("{0:0.00}GB" -F ($_.FreeSpace / 1GB)) }; Alignment="Right"; Width=9 } `
            , @{Name = "空き容量(%)"; Expression = { ("{0:0.00}%" -F ($_.FreeSpace / $_.Size * 100)) }; Alignment="Right"; Width=10 } `

■出力結果

サーバ             ドライブレター                 容量       使用量  空き容量(GB)    空き容量(%)
---             -------                 --       ---  --------    -------
192.168.0.1   C:                226.76GB   81.65GB  145.11GB     63.99%
192.168.0.1   D:                  0.00GB    0.00GB    0.00GB           
192.168.0.1   H:                289.85GB    2.95GB  286.90GB     98.98%
192.168.0.1   S:                135.93GB  124.02GB   11.91GB      8.76%
192.168.0.1   T:                330.00GB  277.76GB   52.24GB     15.83%