Powershell’s Get-Process command lists the processes run by all users, which is not always useful, e.g. when running scripts for users with non-elevated rights.
Here is a workaround function:
1 2 3 4 5 6 7 8 9 10 11 |
#Alternative to Get-Process (get processes of all users) #This script gets only the processes run by the current user. function Get-UserProcess($ProcName) { $owners = @{} gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user} $result = get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}} | Where ({$_.Owner -eq $env:USERNAME -and $_.processname -eq $ProcName}) return $result } #Run it Get-UserProcess Explorer |
Comments