Skip to content

Instantly share code, notes, and snippets.

@DBremen
Last active March 16, 2017 12:46
Show Gist options
  • Select an option

  • Save DBremen/260d138d2e48ea06f0fb to your computer and use it in GitHub Desktop.

Select an option

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
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