Report CPU usage % by PID

Welcome Forums General PowerShell Q&A Report CPU usage % by PID

This topic contains 1 reply, has 2 voices, and was last updated by

9 months, 1 week ago.

  • Author
  • #98682

    Points: 1
    Rank: Member

    We want to report CPU usage % by PID. We have a Powershell script in place; however it reports Instance Name, not PID. The Powershell script we have is:
    $Samples = (Get-Counter "\Process($Processname*)\% Processor Time" -ErrorAction SilentlyContinue).CounterSamples
    $Samples | Select InstanceName, @{Name="CPU";Expression={[Decimal]::Round(($_.CookedValue / 2), 2)}}

    Is it possible to report PID?

  • #98688

    Points: 386
    Helping Hand
    Rank: Contributor

    Not from this command. You can fudge it as long as the process you're after is the only instance of the same name, but as soon as you get more than one process with the same name (easy example would be Chrome) you have no way of determining ID from the data that this counter reports.

    I would be looking to see if you can use Get-Counter to in some way pull this data by PID instead, and pull PIDs from Get-Process — OR just try to get this data via Get-Process, which always returns the IDs anyway.

The topic ‘Report CPU usage % by PID’ is closed to new replies.