Skip to content

Instantly share code, notes, and snippets.

@Rudde
Created September 7, 2018 13:44
Show Gist options
  • Save Rudde/75aba74cb7a5071b70fc369b1db6020a to your computer and use it in GitHub Desktop.
Save Rudde/75aba74cb7a5071b70fc369b1db6020a to your computer and use it in GitHub Desktop.
Function Format-FileSize() {
Param ([long]$size)
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
Else {"0 byte"}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment