{"id":4441,"date":"2009-02-11T21:17:41","date_gmt":"2009-02-11T21:17:41","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2009\/02\/11\/stopping-every-instance-of-powershell-exe-except-the-one-im-in\/"},"modified":"2019-02-18T13:12:48","modified_gmt":"2019-02-18T20:12:48","slug":"stopping-every-instance-of-powershell-exe-except-the-one-im-in","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/stopping-every-instance-of-powershell-exe-except-the-one-im-in\/","title":{"rendered":"Stopping Every Instance of PowerShell.exe (except the one I&#039;m in)"},"content":{"rendered":"<p>Our Test Architect just dropped by my office and pitched me a PowerShell question with a nice, quick answer.<\/p>\n<p>He wanted to stop every process of a particular name, except for the instance that was running the script.<\/p>\n<p>You can do this in one nice pipeline:<\/p>\n<blockquote>\n<p><em>Get-Process Powershell&#160; | Where-Object { $_.ID -ne $pid } | Stop-Process<\/em><\/p>\n<\/blockquote>\n<p>Get-Process takes a positional parameter (name), which is a wildcard that supplies the name of the process.&#160; It returns back a bunch of ProcessInfo objects, which have a property, ID (the process ID).&#160; $pid is a variable that will tell you the current process ID in PowerShell.&#160; Where-Object { $_.ID -ne $pid } simply returns every instance that isn&#8217;t the current instance.&#160; Stop-Process takes ProcessInfo from objects, and will stop the processes that were piped into it (which is now every instance of PowerShell except the one I&#8217;m in).<\/p>\n<p>Another day, another PowerShell question answered.<\/p>\n<p>Hope this Helps,<\/p>\n<p>James Brundage [MSFT]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our Test Architect just dropped by my office and pitched me a PowerShell question with a nice, quick answer. He wanted to stop every process of a particular name, except for the instance that was running the script. You can do this in one nice pipeline: Get-Process Powershell&#160; | Where-Object { $_.ID -ne $pid } [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4441","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Our Test Architect just dropped by my office and pitched me a PowerShell question with a nice, quick answer. He wanted to stop every process of a particular name, except for the instance that was running the script. You can do this in one nice pipeline: Get-Process Powershell&#160; | Where-Object { $_.ID -ne $pid } [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=4441"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4441\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=4441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=4441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=4441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}