{"id":1863,"date":"2014-03-06T11:59:00","date_gmt":"2014-03-06T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/03\/06\/powertip-stop-a-powershell-job\/"},"modified":"2014-03-06T11:59:00","modified_gmt":"2014-03-06T11:59:00","slug":"powertip-stop-a-powershell-job","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-stop-a-powershell-job\/","title":{"rendered":"PowerTip: Stop a PowerShell Job"},"content":{"rendered":"<p><b>Summary<\/b>: Learn how to stop an unwanted Windows PowerShell job.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;How can I stop an over-running Windows PowerShell job?<\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;Even though this is not something you&rsquo;d normally do, creating an infinite loop is a common (and <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; potentially, very embarrassing) error. This job will run forever:<\/p>\n<p style=\"margin-left:120px\">Start-Job -ScriptBlock {while ($true){sleep -Seconds 10}}<\/p>\n<p style=\"margin-left:60px\">When you realize that your job is over-running, use the&nbsp;<b>Stop-Job<\/b>&nbsp;cmdlet:<\/p>\n<p style=\"margin-left:120px\">Stop-Job -Id 14<\/p>\n<p style=\"margin-left:60px\">You can then hide the evidence by using&nbsp;<b>Remove-Job<\/b>&nbsp;to delete the job. <br \/>You can test the data in the stopped job with&nbsp;<b>Receive-Job<\/b>, if desired, before you delete the job.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to stop an unwanted Windows PowerShell job. &nbsp;How can I stop an over-running Windows PowerShell job? &nbsp;Even though this is not something you&rsquo;d normally do, creating an infinite loop is a common (and &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; potentially, very embarrassing) error. This job will run forever: Start-Job -ScriptBlock {while ($true){sleep -Seconds [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[193,189,4,45],"class_list":["post-1863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-background-jobs","tag-richard-siddaway","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to stop an unwanted Windows PowerShell job. &nbsp;How can I stop an over-running Windows PowerShell job? &nbsp;Even though this is not something you&rsquo;d normally do, creating an infinite loop is a common (and &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; potentially, very embarrassing) error. This job will run forever: Start-Job -ScriptBlock {while ($true){sleep -Seconds [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=1863"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1863\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=1863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}