As an administrator I can get a users processes by running this
Get-Process -IncludeUserName | Where UserName -match test
But as a non-administrator I can't use -IncludeUserName
because "The 'IncludeUserName' parameter requires elevated user rights".
So if I'm logged on as the user test, how do I list only his processes and not everything that's running?
You can do that through WMI. Here is an excerpt of an article you can find here.
$View = @(
@{l='Handles';e={$_.HandleCount}},
@{l='NPM(K)';e={ (Get-Process -Id $_.ProcessId).NonpagedSystemMemorySize/1KB -as [int]}},
@{l='PM(K)';e={ $_.PrivatePageCount/1KB -as [int]}},
@{l='WS(K)';e={ $_.WorkingSetSize/1KB -as [int]}},
@{l='VM(M)';e={ $_.VirtualSize/1mB -as [int]}},
@{l='CPU(s)';e={ (Get-Process -Id $_.ProcessId).CPU -as [int]}},
@{l='Id';e={ $_.ProcessId}},
'UserName'
@{l='ProcessName';e={ $_.ProcessName}}
)
Get-WmiObject Win32_Process | % { $_ |
Add-Member -MemberType ScriptProperty -Name UserName -Value {
'{0}\{1}' -f $this.GetOwner().Domain,$this.GetOwner().User
} -Force -PassThru
} | ? UserName -match $env:USERNAME | ft $View -AutoSize