Getting percentage CPU Time and owner for processes

Welcome Forums General PowerShell Q&A Getting percentage CPU Time and owner for processes

  • This topic has 2 replies, 3 voices, and was last updated 3 months ago by
    Participant
    .
Viewing 2 reply threads
  • Author
    Posts
    • #206286
      Participant
      Topics: 23
      Replies: 15
      Points: 28
      Rank: Member

      I need to collect the pecentage of CPU time (percentage, not total CPU time ad displayed by command TASKLIST /V) for all the processes on a Windows server.

      I see I can get the values I need by using the command:

      wmic path Win32_PerfFormattedData_PerfProc_Process where “PercentProcessorTime > 0” get PercentProcessorTime, Name, idprocess

      However, I need to get 2 additional information: a timestamp with the time the command was executed, and the user associated with the process.

      Is there any sample I can start from?

      Regards

      marius

    • #206310
      Moderator
      Topics: 3
      Replies: 218
      Points: 1,188
      Helping Hand
      Rank: Community Hero

      Hi Marius,

      Did you search on Bing/Google? There are hell lot of answers for your requirement…

      https://stackoverflow.com/questions/39943928/listing-processes-by-cpu-usage-percentage-in-powershell

      Please go though the thread completely then you will get your answer.

      Still if you don’t understand anything please do let us know.

      Thank you.

    • #206361
      Participant
      Topics: 48
      Replies: 194
      Points: 767
      Helping Hand
      Rank: Major Contributor

      How about this?

      
      $Process = Get-wmiobject win32_process -computername $computername | select *,@{Name='Owner';Expression={($_.GetOwner()).User}}
      $Perfdata = Get-wmiobject win32_perfformatteddata_perfproc_process -computername $computername | ?{($_.PercentProcessorTime -gt 0) -And ($_.Name -notmatch '_Total|Idle|system')}
      $Results = @()
      foreach($item in $Perfdata) {
      $Results += [PSCustomObject] @{
      Name = $($item.Name)
      ID = $($item.IDProcess)
      PercentProcessorTime = $($item.PercentProcessorTime )
      Owner = ($($Process | ?{$_.ProcessId -eq $Item.IDProcess})).Owner
      }
      }
      
      

       

       

Viewing 2 reply threads
  • The topic ‘Getting percentage CPU Time and owner for processes’ is closed to new replies.