header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Stop-Process Powershell
Last Post 30 Oct 2007 10:12 PM by Poshoholic. 11 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
ambersUser is Offline
New Member
New Member
Posts:16
Avatar

--
30 Oct 2007 06:24 AM  

Is there a way to kill all instances of the powershell process except for the active one that I'm using or at least kill it last?  While testing with Task Scheduler and Powershell I have had multiple occassions of the WMI service hanging and leading to several instances of the powershell process running.  When I use stop-process powershell it kills my current session.  My temporary workaround was to launch it from VBScript in Task Scheduler, but I'd rather continue my testing without it.

JasonUser is Offline
New Member
New Member
Posts:3
Avatar

--
30 Oct 2007 07:14 AM  
you can try this:
 gps powershell | ? {$_.ID -ne ([System.diagnostics.process]::getcurrentprocess()).id } | kill 
It will kill all powershell process except the current one.
bsonposhUser is Offline
Basic Member
Basic Member
Posts:393
Avatar

--
30 Oct 2007 01:27 PM  
Or even easier. Use the build in $pid

PS> Get-process "powershell" | where{$_.id -ne $pid} | stop-process
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
SAPIENScripterUser is Offline
New Member
New Member
Posts:45

--
30 Oct 2007 05:09 PM  
Or even better since tomorrow is Halloween:

ps "powershell" | where{$_.id -ne $pid} | KILL

I've seen too many vampire movies lately. :-)
Jeffery Hicks
Microsoft PowerShell MVP
http://blog.sapien.com
http://www.scriptinganswers.com

"Those who forget to script are doomed to repeat their work."
bsonposhUser is Offline
Basic Member
Basic Member
Posts:393
Avatar

--
30 Oct 2007 05:39 PM  
ps "powershell" | ?{$_.id -ne $pid} | kill
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
ambersUser is Offline
New Member
New Member
Posts:16
Avatar

--
30 Oct 2007 09:58 PM  

Is there a list of the built-in variables anywhere?  If I had know $pid existed I think I would have been able to figure this one out.

Of course, reading your responses was worth the question.  Kudos to Brandon for most concise, Jeff gets bonus points for death humor.

SAPIENScripterUser is Offline
New Member
New Member
Posts:45

--
30 Oct 2007 10:00 PM  
at a PS prompt type:

get-variable
Jeffery Hicks
Microsoft PowerShell MVP
http://blog.sapien.com
http://www.scriptinganswers.com

"Those who forget to script are doomed to repeat their work."
PoshoholicUser is Offline
PowerShell MVP
New Member
New Member
Posts:38
Avatar

--
30 Oct 2007 10:04 PM  

You can also find a one-liner that will give you all variables with their descriptions here:

http://poshoholic.com/2007/09/18/essential-powershell-know-your-system-variables/

-
Kirk Munro
Poshoholic
http://poshoholic.com

bsonposhUser is Offline
Basic Member
Basic Member
Posts:393
Avatar

--
30 Oct 2007 10:07 PM  
Kirk.. that is good stuff!
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
ambersUser is Offline
New Member
New Member
Posts:16
Avatar

--
30 Oct 2007 10:07 PM  
Hmmm... it couldn't have been that easy he said. :)  Thanks Jeffery.
bsonposhUser is Offline
Basic Member
Basic Member
Posts:393
Avatar

--
30 Oct 2007 10:08 PM  
although it should be noted... that isnt really a one-liner :)
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
PoshoholicUser is Offline
PowerShell MVP
New Member
New Member
Posts:38
Avatar

--
30 Oct 2007 10:12 PM  
Hey hay, see all those backticks at the end of the lines in my post? ;)  It's only on multiple lines in my blog to improve readability.

-
Kirk Munro
Poshoholic
http://poshoholic.com
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer