make your own suffix like gb, mb, etc

Welcome Forums General PowerShell Q&A make your own suffix like gb, mb, etc

This topic contains 2 replies, has 3 voices, and was last updated by

1 year, 7 months ago.

  • Author
  • #74920

    Points: 551
    Helping Hand
    Rank: Major Contributor

    Is there a way to make your own suffix like gb, mb, etc? Like 10d for 10 days, 10m for 10 minutes, etc.

  • #74924

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

  • #75065

    Points: 67
    Rank: Member

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

The topic ‘make your own suffix like gb, mb, etc’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort