Formatting Help

Welcome Forums General PowerShell Q&A Formatting Help

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

1 year ago.

  • Author
  • #84376

    Points: 27
    Rank: Member

    Hi PowerGuyz,
    I am very new to this forum and also exploring PS too. Now I used to run Get-process command with memory values in MB format. I don't want to change the property name, but the value I am expecting in MB. Now the problem is, the output is coming as custom property name. How should I manage the same?
    Also please guide me if there is any shortcut to perform the same.
    Here is the command:

    Get-Process |select id, ProcessName, {$ /1mb -as [int]}, {$_.vm /1mb -as [int]}, cpu -First 5|ft -AutoSize

    Id ProcessName $ /1mb -as [int] $_.vm /1mb -as [int] CPU
    — ———– ——————– ——————– —
    9524 AcroRd32 98 284 30.5137956
    10564 AcroRd32 8 83 6.9732447
    2188 armsvc 1 43 0.2496016
    2164 CcmExec 45 224 36.7382355
    2304 chrome 2 64 0.0156001


  • #84379

    Points: 0
    Rank: Member

    You want something like this

    Get-Process |
    select Id, ProcessName, 
    @{Name = 'PM(M)'; Expression = {$ /1mb -as [int]}}, 
    @{Name = 'VM(M)'; Expression = {$_.vm /1mb -as [int]}}, 
    CPU -First 5 |
    Format-Table -AutoSize
    • #84383

      Points: 27
      Rank: Member

      Hi Richard,

      You are right, I want this exact same. But is it mandatory to do write @{Name = 'PM(M)'; Expression = {$ /1mb -as [int]}} each time I need some conversation of MB/GB from small units? Is there any tricky way to perform that.


    • #84385

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

      Yes, it's mandatory.

  • #84380

    Points: 246
    Helping Hand
    Rank: Participant

    Dou you mean something like this:

    Get-Process | 
        Select-Object -Property id, ProcessName, @{Name='PM';Expression={$ /1mb -as [int]}}, @{Name='VM';Expression={$_.vm /1mb -as [int]}}, cpu -First 5 | 
            Format-Table -AutoSize


The topic ‘Formatting Help’ is closed to new replies.