Home > database >  Powershell - Get-Process's ProcessName is truncated on macOS
Powershell - Get-Process's ProcessName is truncated on macOS

Time:07-26

I'm using Powershell 7.2.5 on macOS 12.5. I had Google Chrome open and ran Get-Process google*, and got truncated ProcessName:

gps google*                    

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
      0     0.00     626.36   5,529.29   33973   1 Google Chrome
      0     0.00     124.94   2,870.73   33993   1 Google Chrome H

Google Chrome H should be Google Chrome Helper or something longer.

gps | sort-object {$_.ProcessName.length} showed that all processnames are truncated to 15 chars.

How do I make Get-Process output without truncation?

I read the help for Get-Process and tried to pipe the output to Format-Custom and Format-List ProcessName -Force, and none of these tricks worked.

CodePudding user response:

Unfortunately, this is not a formatting problem: At least up to the .NET version underlying PowerShell Core 7.3.0-preview.6, .NET , .NET 7.0.0-preview.6.22324.4, the .ProcessName property value is limited to 15 chars.

This is a known problem, and there is a known fix, but no one has stepped up to implement it yet - see GitHub issue #52860

A - computationally expensive - workaround is to use a call to the native ps utility, via a calculated property:

Get-Process google* | 
  Select-Object Id, 
                @{ n='ProcessName'; e={ Split-Path -Leaf (ps -p $_.Id -o comm=) }

Note: The above reports just the process ID and the (full) process name.

More work is needed if you want the same display columns as you would get by default, only with the full process names:

Get-Process google* | ForEach-Object {
  $copy = $_ | Select-Object *
  $copy.ProcessName = Split-Path -Leaf (ps -p $_.Id -o comm=)
  $copy.pstypenames.Insert(0, 'System.Diagnostics.Process')
  $copy
}
  • Related