INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Need to list top 5 CPU Intensive processes including owner

Need to list top 5 CPU Intensive processes including owner

Need to list top 5 CPU Intensive processes including owner

(OP)
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.

RE: Need to list top 5 CPU Intensive processes including owner

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.

RE: Need to list top 5 CPU Intensive processes including owner

(OP)
Thank You. I have been working with something similar, but am having trouble trying to incorporate userid/owner.

RE: Need to list top 5 CPU Intensive processes including owner

don't remember where i found this, but it works for me.

CODE --> powershell

$owners = @{}
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}} 

RE: Need to list top 5 CPU Intensive processes including owner

(OP)
Thank You! I will tinker with this!

RE: Need to list top 5 CPU Intensive processes including owner

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close