Getting percentage CPU Time and owner for processes

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?



Hi Marius,

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

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.

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