I know, but at least it's a starting point. I'm still looking for a better 
place to pull the cpu stuff from.

Christopher Catlett
Consultant | Detroit
[MCTS_2013_small]

Sogeti USA
Office 248-876-9738 |Fax 877.406.9647
26957 Northwestern Highway, Suite 130, Southfield, MI 48033-8456
www.us.sogeti.com<http://www.us.sogeti.com/>

From: [email protected] [mailto:[email protected]] On 
Behalf Of Damien Solodow
Sent: Monday, September 09, 2013 5:21 PM
To: [email protected]
Subject: [powershell] RE: looking for a way to pull top 5 processes (cpu 
utilization) reliably.

One problem with it though is that the CPU is showing total CPU cycles of that 
process rather than CPU time consumed now which you said wasn't what you wanted.

I think this might be closer to what you want:
gwmi Win32_PerfFormattedData_PerfProc_Process -Filter{NOT NAME = "Idle" AND NOT 
NAME = "_Total"} |
sort percentprocessortime -Descending |
select -first 5 name,percentprocessortime

One thing that is likely to be an issue with the 
Win32PerfFormattedData_PerfProc is that it only updates periodically, so it's 
not real time. I think the update interval is around 3-5 seconds though.

DAMIEN SOLODOW
Systems Engineer
317.447.6033 (office)
317.447.6014 (fax)
HARRISON COLLEGE

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of 
[email protected]<mailto:[email protected]>
Sent: Monday, September 09, 2013 4:55 PM
To: [email protected]<mailto:[email protected]>
Subject: [powershell] RE: looking for a way to pull top 5 processes (cpu 
utilization) reliably.

The below is the best method I've found.

# set an array and get the owner of all processes through wmi, for later in the 
script.
$owners = @{}
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}

#Get all processes, except those running as (system, local/network system)
$Proc = Get-Process | Select CPU, ProcessName, ID, 
@{l="Owner";e={$owners[$_.id.tostring()]}} | where {$_.Owner -ne "SYSTEM" -AND 
$_.Owner -ne "NETWORK SERVICE" -AND $_.Owner -ne "LOCAL SERVICE"} | Sort-Object 
CPU -Descending
write-output $Proc | Select -first 5 | FT -a

Christopher Catlett
Consultant | Detroit
[MCTS_2013_small]

Sogeti USA
Office 248-876-9738 |Fax 877.406.9647
26957 Northwestern Highway, Suite 130, Southfield, MI 48033-8456
www.us.sogeti.com<http://www.us.sogeti.com/>

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of Catlett, Christopher
Sent: Monday, September 09, 2013 3:23 PM
To: [email protected]<mailto:[email protected]>
Subject: [powershell] RE: looking for a way to pull top 5 processes (cpu 
utilization) reliably.

Get-process doesn't return the process owner or cpu percentage, so it seems 
straight wmi is better in this case (for that part at least).

Christopher Catlett
Consultant | Detroit
[MCTS_2013_small]

Sogeti USA
Office 248-876-9738 |Fax 877.406.9647
26957 Northwestern Highway, Suite 130, Southfield, MI 48033-8456
www.us.sogeti.com<http://www.us.sogeti.com/>

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of Damien Solodow
Sent: Monday, September 09, 2013 2:51 PM
To: [email protected]<mailto:[email protected]>
Subject: [powershell] RE: looking for a way to pull top 5 processes (cpu 
utilization) reliably.

Install Windows Management Framework and do it with PowerShell? :)

DAMIEN SOLODOW
Systems Engineer
317.447.6033 (office)
317.447.6014 (fax)
HARRISON COLLEGE

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of 
[email protected]<mailto:[email protected]>
Sent: Monday, September 09, 2013 2:32 PM
To: [email protected]<mailto:[email protected]>
Subject: [powershell] looking for a way to pull top 5 processes (cpu 
utilization) reliably.

I can't seem to find a good way.
These are 2003r2 machines (citrix servers...)

It seems like the only way is going to be through wmi, since get-process tells 
me total cpu time since the process started (totally unhelpful)

'Win32_PerfFormattedData_PerfProc_Process where percentProcessorTime' seems to 
return intermittent results. I fired up firefox playing a html5 video on my 
test server (in task manager its using 40% of the cpu) but it doesn't show up 
on the perfdata list.

Anyone got idea's?

Christopher Catlett
Consultant | Detroit
[MCTS_2013_small]

Sogeti USA
Office 248-876-9738 |Fax 877.406.9647
26957 Northwestern Highway, Suite 130, Southfield, MI 48033-8456
www.us.sogeti.com<http://www.us.sogeti.com/>


================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1


================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

<<inline: image001.jpg>>

Reply via email to