PowerShell Logo Small

Register-EngineEvent



This is the built-in help made by Microsoft for the command 'Register-EngineEvent', 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

Subscribes to events that are generated by the Windows PowerShell engine and by the New-Event cmdlet.

SYNTAX


Register-EngineEvent [-SourceIdentifier] <string> [[-Action] <scriptblock>] [-Forward] [-MessageData <psobject>] [-SupportEvent] [<CommonParamete
rs>]



Search powershellhelp.space

DESCRIPTION


The Register-EngineEvent cmdlet subscribes to events that are generated by the Windows PowerShell engine and the New-Event cmdlet. Use the Source
Identifier parameter to specify the event.

You can use this cmdlet to subscribe to the "Exiting" engine event and events generated by the New-Event cmdlet. These events are automatically a
dded to your event queue in your session without subscribing. However, subscribing lets you forward the events, specify an action to respond to t
he events, and cancel the subscription.

When the subscribed event is raised, it is added to the event queue in your session. To get events in the event queue, use the Get-Event cmdlet.

When you subscribe to a event, an event subcriber is added to your session. To get the event subscribers in the session, use the Get-EventSubscri
ber cmdlet. To cancel the subscription, use the Unregister-Event cmdlet, which deletes the event subscriber from the session.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=135243
Register-ObjectEvent
Register-WmiEvent
Unregister-Event
Get-Event
New-Event
Remove-Event
Wait-Event
Get-Job
Receive-Job
Remove-Job
Wait-Job

REMARKS

<

Examples


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

C:\PS>$s = new-pssession -computername Server01, Server02

C:\PS> invoke-command -session $s { Register-EngineEvent -sourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -forward }



Description
-----------
This command registers for a Windows PowerShell engine event on two remote computers.

The first command creates a PSSession on each of the remote computers.

The second command uses the Invoke-Command cmdlet to run the Register-EngineEvent command in the remote sessions.

The Register-EngineEvent command uses the SourceIdentifier parameter to identify the event. It uses the Forward parameter to forward the events f
rom the remote session to the local session.








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

C:\PS>$j = register-engineEvent -sourceIdentifier PowerShell.ProcessCreated -action { $processName | add-content processLog.txt }

C:\PS> get-event

C:\PS> $results = $j | receive-job

C:\PS> unregister-event PowerShell.ProcessCreated



Description
-----------
This command shows how to use the Job cmdlets to manage the event job object that Register-EngineEvent returns when you use the Action parameter.

An event job is managed just like any other Windows PowerShell job. For more information, see about_jobs. In this example, the Receive-Job cmdlet
is used to get the results of the job.

To delete the job from the session, use Remove-Job. To cancel your event subscription, use the Unregister-Event cmdlet. To delete the events in t
he event queue, use Remove-Event.