PowerShell Logo Small

Wait-Event



This is the built-in help made by Microsoft for the command 'Wait-Event', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Waits until a particular event is raised before continuing to run.

SYNTAX


Wait-Event [[-SourceIdentifier] [<String>]] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]]
[-Timeout [<Int32>]] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Wait-Event cmdlet suspends execution of a script or function until a particular event is raised. Execution resumes when the event is detected. To cancel the wait, press
CTRL+C.


This feature provides an alternative to polling for an event. It also allows you to determine the response to an event in two different ways: by using the Action parameter
of the event subscription and by waiting for an event to return and then respond with an action.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=294026
Get-Event
Get-EventSubscriber
New-Event
Register-EngineEvent
Register-ObjectEvent
Register-WmiEvent
Remove-Event
Unregister-Event
Wait-Event

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>wait-event



This command waits for the next event that is raised.










-------------------------- EXAMPLE 2 --------------------------

PS C:\>wait-event -sourceIdentifier "ProcessStarted"



This command waits for the next event that is raised and that has a source identifier of "ProcessStarted".










-------------------------- EXAMPLE 3 --------------------------

PS C:\>$timer.Interval = 2000
PS C:\>$timer.Autoreset = $false
PS C:\>$timer.Enabled = $true; Wait-Event Timer.Elapsed

# After 2 seconds

EventIdentifier : 12
Sender : System.Timers.Timer
SourceEventArgs : System.Timers.ElapsedEventArgs
SourceArgs : {System.Timers.Timer, System.Timers.ElapsedEventArgs}
SourceIdentifier : Timer.Elapsed
TimeGenerated : 6/10/2008 3:24:18 PM
MessageData :
ForwardEvent : False



This command uses the Wait-Event cmdlet to wait for a timer event on a timer that is set for 2000 milliseconds.










-------------------------- EXAMPLE 4 --------------------------

PS C:\>wait-event -sourceIdentifier "ProcessStarted" -timeout 90



This command waits up to 90 seconds for the next event that is raised and that has a source identifier of "ProcessStarted". If the specified time expires, the wait ends.