Scripting. Powershell, VMware, Windows, Active Directory & Exchange. All that kind of stuff…..
RSS icon Email icon Home icon
  • PowerShell 2.0: One Cmdlet at a Time #101 Wait-Process

    Posted on May 18th, 2010 Jonathan Medd No comments

    Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Wait-Process cmdlet.

    What can I do with it?

    Wait for a process to stop before proceeding further.

    Example:

    Open an instance of Notepad. Use Wait-Process to pause the console session until Notepad is closed.

    Notepad
    Wait-Process -Name Notepad

    You will notice that the console pauses whilst Notepad is open

    Wait-Process1

    Once Notepad is closed, control of the session is returned to the user.

    Wait-Process2

    How could I have done this in PowerShell 1.0?

    Store the result of Get-Process Notepad in a variable, then use the WaitForExit method to wait for the process to stop.

    Notepad
    $Process = Get-Process Notepad
    $Process.WaitForExit()

    1000 things 1% better

    Leave a reply