Get Process Owners
I really like the @PowerTip blog series but I find myself wanting to talk back with more than 120 characters. Please enable comments @PowerTip. Comments are enabled for authenticated users. In the meantime, I’ll blog my comments.
function Get-PSOwner($searchString)
{
$foundProcess = ps $searchString
if($foundProcess -eq $null) { return; }
gwmi Win32_Process -Filter ("Handle={0}" -f $foundProcess.id ) |
% { Add-Member `
-InputObject $_ `
-MemberType NoteProperty `
-Name Owner `
-Value ($_.GetOwner().User) `
-PassThru } |
select Name, Handle, Owner
}
The four minor changes I made to the @PowerTip script are: 1) it’s functionized, 2) the input is a search string for process (wildcards accepted), 3) it spits out the correct errors if the process can’t be found, and 4) the process handle is added to the results.
Download the script here: http://bitbucket.org/xcud/powershell-snippets/src/tip/Get-PSOwner.psm1