PowerTip: Stop a PowerShell Job

Doctor Scripto

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.


Discussion is closed.

Feedback usabilla icon