List process for current user

As an administrator, I can get user processes by doing this

Get-Process -IncludeUserName | Where UserName -match test

But as a non-administrator, I cannot use -IncludeUserName becuase "The IncludeUserName parameter requires elevated user rights."

So, if I am registered as a user test, how do I list only its processes, and not everything that works?

+8
powershell
source share
3 answers

You can do this through WMI. Here is an excerpt from 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 
+5
source share

Get-Process alone will not give you this information, you will need WMI:

 $owners = @{} gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user} $ps = get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}} foreach($p in $ps) { if($p.Owner -eq $env:USERNAME) { $p } } 
+6
source share

Thanks for your code. Based on this, I created a modified version that allows users to kill (a subset) of their own processes:

 #Script to allow users to kill (a subset of) their own processes #Based on : https://stackoverflow.com/questions/35195221/list-process-for-current-user #Previously we used Task Nanny created by Michel Stevelmans which is a lot faster, but it did not show a process that was causing issues for our users. $UserProcesses = @() $Owners = @{} Get-WmiObject win32_process | Foreach{$owners[$_.handle] = $_.getowner().user} $Processes = Get-Process | select processname,Description,Id,@{l="Owner";e={$owners[$_.id.tostring()]}} Foreach($Process in $Processes) { IF($process.Owner -eq $env:USERNAME) { $UserProcesses += $Process } } $UserProcessesToExclude = @( 'concentr', #Citrix Connection Center 'conhost', #Console Window Host 'dwm', #Desktop Windows Manager 'explorer', #Explorer 'Receiver', #Citrix Receiver Application 'rundll32', #Windows host process (Rundll32) 'ssonsvr', #Citrix Receiver 'taskhost' #Host Process for Windows Tasks 'wfcrun32' #Citrix Connection Manager 'wfshell' #Citrix wfshell shell ) $UserProcesses | Where{$_.ProcessName -notin $UserProcessesToExclude} | Out-GridView -Title 'Task killer - Select the process(es) you want to kill. Hold CTRL to select multiple processes.' -PassThru | Foreach{Stop-Process -id $_.Id} 
+1
source share

All Articles