Formatting Help

This topic contains 4 replies, has 4 voices, and was last updated by  Don Jones 3 weeks, 3 days ago.

  • Author
    Posts
  • #84376

    Sankhadip Roy
    Participant

    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, {$_.pm /1mb -as [int]}, {$_.vm /1mb -as [int]}, cpu -First 5|ft -AutoSize

    Output:
    Id ProcessName $_.pm /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

    Regards,
    Roy.

  • #84379

    Richard Siddaway
    Moderator

    You want something like this

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

      Sankhadip Roy
      Participant

      Hi Richard,

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

      Regards
      Roy.

    • #84385

      Don Jones
      Keymaster

      Yes, it's mandatory.

  • #84380

    Olaf Soyk
    Participant

    Dou you mean something like this:

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

    ?

You must be logged in to reply to this topic.