PowerShell for Windows Admins

Jan 15 2014   2:02PM GMT

Win32_Process examples: get process owner

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Moving on with examples of using Win32_Process you can find the process owner:

function get-procowner {
param (
[string]$computername = $env:COMPUTERNAME

Get-CimInstance -ClassName Win32_Process -ComputerName $computername |
foreach {
$owner = Invoke-CimMethod -InputObject $psitem -MethodName GetOwner

$props = [ordered]@{
Name = $psitem.Name
Domain = $owner.Domain
User = $owner.User
ComputerName = $psitem.PSComputerName

New-Object -TypeName PSObject -Property $props

Use the same param block as before to pass a computername – defaulted to local machine.

For each of the Win32_Process objects get the corresponding owner using the GetOwner method.

Create an ordered hash table for the properties and output a PSObject using those properties

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: