Win32_Process examples: get process owner

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

This entry was posted in CIM, PowerShell and WMI, PowerShell V3, PowerShell v4. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s