PowerTip: Stop a PowerShell Job

PowerTip: Stop a PowerShell Job

  • Comments 4
  • Likes

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.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment