Is there a way to make your own suffix like gb, mb, etc? Like 10d for 10 days, 10m for 10 minutes, etc.
Yes. PowerShell is open-source; you’d need to fork the repository, contribute that change, and then submit a pull request.
But other than changing the core code, no.
I’ve used this Format-FileSize function. Just wrap this function around the number you want to format. I’ve only found a limited use for it though.
Function Format-FileSize() { Param ( [parameter(ValueFromPipeline=$true)] [int64]$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 {""} }
I’ve also seen forum posts where they modify the default view for System.IO.FileInfo objects. A new FileSize property is added that essentially adds a switch statement to change the length property. Take a look at the help files for Update-TypeData.