Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to list top 5 CPU Intensive processes including owner

Status
Not open for further replies.

bhimmler

IS-IT--Management
Dec 4, 2015
8
0
0
US
Having difficulty with a task... I need to list top 5 CPU Intensive processes including owner.

ANY Help is appreciated!

Hoping someone out there has done the same or something similar that they can share.
 
I don't have anything that gets the owner, but this should get you close:

Code:
$top_procs = 5
$server = "MyServer"

gwmi -computer $server Win32_PerfFormattedData_PerfProc_Process | where {$_.name -NOTLIKE 'IDLE' -AND $_.name -NOTLIKE '_Total'} | sort PercentProcessorTime -desc | select Name,PercentProcessorTime | Select -First $top_procs | ft -auto


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Thank You. I have been working with something similar, but am having trouble trying to incorporate userid/owner.
 
don't remember where i found this, but it works for me.

Code:
$owners = @{}
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}}
 
I haven't verified the information, but see if this works for you.

Code:
$top_procs = 5
$server = "MyServer"

$processes = gwmi -computer $server Win32_PerfFormattedData_PerfProc_Process | where {$_.name -NOTLIKE 'IDLE' -AND $_.name -NOTLIKE '_Total'} | sort PercentProcessorTime -desc | select Name,PercentProcessorTime,Owner,IDProcess,Handles | Select -First $top_procs

foreach ($process in $processes)
	{
	 [string]$handles = (get-process -computername $server | where {$_.ID -eq $proc_id} | select handles)
 	 $handles_start = $handles.IndexOf("=") + 1
	 $handles_end = $handles.length - 1
	 $handles = $handles.substring($handles_start,($handles_end-$handles_start))
	 $process.handles = $handles

	 [string]$owner = gwmi win32_process -ComputerName $server  | where {$_.handles -eq $handles} | select {$_.getowner().user}
	 $owner_start = $owner.IndexOf("=") + 1
	 if ($owner_start -gt 1)
		{
		 $owner_end = $owner.length - 1
		 $owner = $owner.substring($owner_start,($owner_end-$owner_start))
		}

	 $process.owner = $owner
	}
	
$processes | ft name,PercentProcessorTime,Owner,IDProcess -autosize


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top