Report CPU usage % by PID

This topic contains 1 reply, has 2 voices, and was last updated by  Joel Sallow 6 days, 4 hours ago.

  • Author
    Posts
  • #98682

    Kevin Berger
    Participant

    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

    Joel Sallow
    Participant

    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.

You must be logged in to reply to this topic.