![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | get-process & stop-process by owner I'm trying to figure out how I can list and stop only those processes that are being run by a specific user like you can with tasklist and taskkill. In otherwords what is the translation of these commands: tasklist /fi "username eq drevlan" taskkill /fi "username eq drevlan" /im calc.exe In powershell using get-process and stop-process. Thank you! --Andrew |
My System Specs![]() |
| | #2 (permalink) |
| | Re: get-process & stop-process by owner I would have thought the object returned from get-process would have a user account, but I couldnt find it (I could have missed it.) Either way... I used wmi. I wrote this script... its a quicky and no promises I did test it and itworked for me... I added the -whatif switch just in case. code ==== function Kill-UserProcess{ param([string]$server,[string]$user,[string]$process,[switch]$Kill,[switch]$whatif) if($server){$processes = Get-WmiObject Win32_Process -ComputerName $server} else{$processes = Get-WmiObject Win32_Process} if($user){ if($kill){if(!$process){Write-Host "Killing all Processes for User[$user]"}} foreach($p in $processes){ if($p.GetOwner().user -match "$user"){ if($process){ if($p.Name -match "$process"){ if($kill){ Write-Host "Killing Process [$($p.Name)] for User [$user]" if($whatif){ write-Host "What if: Performing operation `"kill`" on Target`"$($p.Name)`"." } } else{ Write-Host "Killing Process $($p.Name)" $p.Terminate() | out-null } return $true } } if($kill){ if($whatif){ write-Host "What if: Performing operation `"kill`" on Target`"$($p.Name)`"." } else{ Write-Host "Killing Process $($p.Name)" $p.Terminate() | out-Null } } else{ Write-Host "$p.Name" } } } }}"Andrew Conrad" <drevlan@gmail.com> wrote in messagenews:78BD196E-0B80-4649-A457-5B9DDAB7850B@microsoft.com...> I'm trying to figure out how I can list and stop only those processes thatare being run by a specific user like you can with tasklist and taskkill.>> In otherwords what is the translation of these commands:>> tasklist /fi "username eq drevlan"> taskkill /fi "username eq drevlan" /im calc.exe>> In powershell using get-process and stop-process.>> Thank you!>> --Andrew |
My System Specs![]() |
| | #3 (permalink) |
| | Re: get-process & stop-process by owner Alright... that didn't turn out so well... I posted on my blog http://bsonposh.com/modules/wordpress/?p=20 "Brandon Shell" <tshell.mask@mk.gmail.com> wrote in message news:ueF9pFaXHHA.1240@TK2MSFTNGP04.phx.gbl... >I would have thought the object returned from get-process would have a user >account, but I couldnt find it (I could have missed it.) Either way... I >used wmi. > > I wrote this script... its a quicky and no promises I did test it and> it worked for me... I added the -whatif switch just in case. > > code > ==== > function Kill-UserProcess{ > param([string]$server,[string]$user,[string]$process,[switch]$Kill,[switch]$whatif) > if($server){$processes = Get-WmiObject Win32_Process -ComputerName > $server} else{$processes = Get-WmiObject Win32_Process} if($user){ > if($kill){if(!$process){Write-Host "Killing all Processes for > User[$user]"}} foreach($p in $processes){ if($p.GetOwner().user -match > "$user"){ if($process){ if($p.Name -match "$process"){ > if($kill){ Write-Host "Killing Process [$($p.Name)] for User > [$user]" if($whatif){ write-Host "What if: Performing > operation `"kill`" on Target`"$($p.Name)`"." } } > else{ Write-Host "Killing Process $($p.Name)" $p.Terminate() | > out-null } return $true } } if($kill){ > if($whatif){ write-Host "What if: Performing operation `"kill`" on > Target`"$($p.Name)`"." } else{ Write-Host "Killing Process > $($p.Name)" $p.Terminate() | out-Null } } else{ > Write-Host "$p.Name" } } } }}"Andrew Conrad" <drevlan@gmail.com> > wrote in > messagenews:78BD196E-0B80-4649-A457-5B9DDAB7850B@microsoft.com...> I'm > trying to figure out how I can list and stop only those processes thatare > being run by a specific user like you can with tasklist and taskkill.>> In > otherwords what is the translation of these commands:>> tasklist /fi > "username eq drevlan"> taskkill /fi "username eq drevlan" /im calc.exe>> > In powershell using get-process and stop-process.>> Thank you!>> --Andrew |
My System Specs![]() |
| | #4 (permalink) |
| | Re: get-process & stop-process by owner Amazing! Thank you so much Brandon you're a superstar! ![]() --Andrew "Brandon Shell" <tshell.mask@mk.gmail.com> wrote in message news:%23NfybVaXHHA.3984@TK2MSFTNGP02.phx.gbl... > Alright... that didn't turn out so well... I posted on my blog > http://bsonposh.com/modules/wordpress/?p=20 > > "Brandon Shell" <tshell.mask@mk.gmail.com> wrote in message > news:ueF9pFaXHHA.1240@TK2MSFTNGP04.phx.gbl... >>I would have thought the object returned from get-process would have a >>user account, but I couldnt find it (I could have missed it.) Either >>way... I used wmi. >> >> I wrote this script... its a quicky and no promises I did test it and>> it worked for me... I added the -whatif switch just in case. >> >> code >> ==== >> function Kill-UserProcess{ >> param([string]$server,[string]$user,[string]$process,[switch]$Kill,[switch]$whatif) >> if($server){$processes = Get-WmiObject Win32_Process -ComputerName >> $server} else{$processes = Get-WmiObject Win32_Process} if($user){ >> if($kill){if(!$process){Write-Host "Killing all Processes for >> User[$user]"}} foreach($p in $processes){ if($p.GetOwner().user -match >> "$user"){ if($process){ if($p.Name -match "$process"){ >> if($kill){ Write-Host "Killing Process [$($p.Name)] for User >> [$user]" if($whatif){ write-Host "What if: Performing >> operation `"kill`" on Target`"$($p.Name)`"." } } else{ >> Write-Host "Killing Process $($p.Name)" $p.Terminate() | >> ull } return $true } } if($kill){ if($whatif){ >> write-Host "What if: Performing operation `"kill`" on >> Target`"$($p.Name)`"." } else{ Write-Host "Killing Process >> $($p.Name)" $p.Terminate() | out-Null } } else{ Write-Host >> "$p.Name" } } } }}"Andrew Conrad" <drevlan@gmail.com> wrote in >> messagenews:78BD196E-0B80-4649-A457-5B9DDAB7850B@microsoft.com...> I'm >> trying to figure out how I can list and stop only those processes thatare >> being run by a specific user like you can with tasklist and taskkill.>> >> In otherwords what is the translation of these commands:>> tasklist /fi >> "username eq drevlan"> taskkill /fi "username eq drevlan" /im calc.exe>> >> In powershell using get-process and stop-process.>> Thank you!>> --Andrew > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| How to stop process? | Vista General | |||
| Failover Guest Cluster -- 'The process cannot access the file becauseit is being used by another process.' | Virtual Server | |||
| Process wlmail.exe doesn't stop...very often | Live Mail | |||
| get the owner of a process | PowerShell | |||
| Bug? Shouldn't Stop-Process automatically match Id if object is a process? | PowerShell | |||