Last active
March 16, 2017 12:46
-
-
Save DBremen/260d138d2e48ea06f0fb to your computer and use it in GitHub Desktop.
Convert file size units based on the number of bytes in a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| filter Get-FileSize { | |
| "{0:N2} {1}" -f $( | |
| if ($_ -lt 1kb) { $_, 'Bytes' } | |
| elseif ($_ -lt 1mb) { ($_/1kb), 'KB' } | |
| elseif ($_ -lt 1gb) { ($_/1mb), 'MB' } | |
| elseif ($_ -lt 1tb) { ($_/1gb), 'GB' } | |
| elseif ($_ -lt 1pb) { ($_/1tb), 'TB' } | |
| else { ($_/1pb), 'PB' } | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment