Quantcast
Channel: WMI – PowerShell for Windows Admins
Viewing all articles
Browse latest Browse all 140

Win32_Process examples: get process owner

$
0
0

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

function get-procowner {
[CmdletBinding()]
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


Viewing all articles
Browse latest Browse all 140

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>