CmdID

CmdID / PowerShell / Cmdlets / Wait

Wait-Event

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

From the PowerShell reference 2 parameters

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Waits until a particular event is raised before continuing to run. 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 <kbd>CTRL</kbd>+<kbd>C</kbd>. 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: - using the Action parameter of the event subscription - waiting for an event to return and then respond with an action

Wait-Event [[-SourceIdentifier] <String>] [-Timeout <Int32>] [<CommonParameters>]

Wait for the next event

Wait-EventIdentify

Wait for an event with a specified source identifier

Wait-Event -SourceIdentifier "ProcessStarted"Identify

Wait for a timer elapsed event

$Timer = New-Object Timers.Timer $objectEventArgs = @{ InputObject = $Timer EventName = 'Elapsed' SourceIdentifier = 'Timer.Elapsed' } Register-ObjectEvent @objectEventArgs $Timer.Interval = 2000 $Timer.AutoReset = $false $Timer.Enabled = $true Wait-Event Timer.ElapsedIdentify

Wait for an event after a specified timeout

Wait-Event -SourceIdentifier "ProcessStarted" -Timeout 90Identify

Its page in the reference: Wait-Event.

Parameters

2 in the PowerShell reference
-SourceIdentifierSpecifies the source identifier that this cmdlet waits for events. By default, Wait-Event waits for any event.
-TimeoutSpecifies the maximum time, in seconds, that Wait-Event waits for the event to occur. The default, -1, waits indefinitely. The timing starts when you submit the Wait-Event command. If the specified time is exceeded, the wait ends and the command prompt returns, even if the event has not been raised. No error message is displayed.