Очень часто получаешь в скрипте вывод в байтах. Если речь идет об очень больших цифрах, то чтобы понять приходится считать разряды
Написал маленькую функу которая форматирует число байт в “human readable” формат
Функцию полезно засунуть в профиль.
Function FB ([double]$bytes){ switch($bytes){ {$bytes -le 1kb} {"$bytes B"; break} {$bytes -le 1mb} {"$([int]($bytes/1kb)) KB"; break} {$bytes -le 1gb} {"$([int]($bytes/1mb)) MB"; break} default {"$([int]($bytes/1gb)) GB"; break} } }
Например так можно посмотреть свободное место на дисках используя WMI:
PS C:\PowerShell> Get-WmiObject Win32_LogicalDisk | >> where {$_.drivetype -eq 3} | >> Format-Table DeviceId, VolumeName, {fb $_.size}, {fb $_.freespace} DeviceId VolumeName fb $_.size fb $_.freespace -------- ---------- ---------- --------------- C: Main 122 GB 28 GB E: Backup 27 GB 20 GB









7.12.2007 в 13:18
We can give each column in the table a more meaningful title.
Format-Table DeviceId, VolumeName, @{Label=”Size”;Expression={fb $_.size}}, @{Label=”Free”;Expression={fb $_.freespace}}
DeviceId VolumeName Size Free
——– ———- —- —-
C: Main 122 GB 28 GB
E: Backup 27 GB 20 GB
We can even control the width of the column @{Label=”Size”;Expression={fb $_.size};Width=15} or if we want pithy version @{l=”Size”;e={fb $_.size};w=15}.
7.12.2007 в 13:21
2 Aleksandar:
I’m just trying to simplify the code for new users
Tnx for comment, I know about this
7.12.2007 в 14:09
I know that you know, I left the comment for new users.
7.12.2007 в 14:09