PowerShell Logo Small

Wait-Event



This is the built-in help made by Microsoft for the command 'Wait-Event', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' 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>] [-Timeout <int>] [<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/?LinkID=135276
Register-ObjectEvent
Register-EngineEvent
Register-WmiEvent
Unregister-Event
Get-Event
New-Event
Remove-Event
Wait-Event
Get-EventSubscriber

REMARKS

<

Examples


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

C:\PS>wait-event



Description
-----------
This command waits for the next event that is raised.








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

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



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








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

C:\PS>$timer.Interval = 2000
C:\PS> $timer.Autoreset = $false
C:\PS> $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



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








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

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



Description
-----------
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.