April 19th, 2014

PowerTip: Use PowerShell to Pause Execution

Summary: Use Windows PowerShell to pause execution for a specific time to wait for a process to exit.

Hey, Scripting Guy! Question I have a process that normally exits within four seconds, and I want to pause the execution of my script to wait 
          for this process to exit. If it does not exit in time, I want an error to occur. How can I easily do this?

Hey, Scripting Guy! Answer Use the Wait-Process cmdlet and specify the name of the process and the wait time:

Wait-Process -Timeout 4 -Name notepad

In this command, if Notepad does not exit within four seconds, and error occurs. 

Author

0 comments

Discussion are closed.