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

 
Participant
6 months, 1 week ago.

  • Author
    Posts
  • #98682

    Participant
    Points: 0
    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

    Participant
    Points: 2
    Rank: Member

    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.