March 6th, 2014

PowerTip: Stop a PowerShell Job

Doctor Scripto
Scripter

Summary: Learn how to stop an unwanted Windows PowerShell job.

Hey, Scripting Guy! Question How can I stop an over-running Windows PowerShell job?

Hey, Scripting Guy! Answer Even though this is not something you’d normally do, creating an infinite loop is a common (and
          potentially, very embarrassing) error. This job will run forever:

Start-Job -ScriptBlock {while ($true){sleep -Seconds 10}}

When you realize that your job is over-running, use the Stop-Job cmdlet:

Stop-Job -Id 14

You can then hide the evidence by using Remove-Job to delete the job.
You can test the data in the stopped job with Receive-Job, if desired, before you delete the job.

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback