Register-EngineEvent - PowerShell command help and examples

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


NAME
Register-EngineEvent
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] [<CommonParameters>]
DESCRIPTION
The Register-EngineEvent cmdlet subscribes to events that are generated by the Windows PowerShell engine and the New-Event cmdlet. Use the SourceIdentifier 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 added to your event queue in your session without subscribing. However, subscribing lets you forward the events, specify an action to respond to the 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-EventSubscriber cmdlet. To cancel the subscription, use the Unregister-Event cmdlet, which deletes the event subscriber from the session.
PARAMETERS
-Action <scriptblock> Specifies commands to handle the events. The commands in the Action run when an event is raised, instead of sending the event to the event queue. Enclose the commands in braces ( { } ) to create a script block. The value of the Action parameter can include the $Event, $EventSubscriber, $Sender, $SourceEventArgs, and $SourceArgs automatic variables, which provide information about the event to the Action script block. For more information, see about_Automatic_Variables. When you specify an action, Register-EngineEvent returns an event job object that represents that action. You can use the Job cmdlets to manage the event job. Required? false Position? 102 Default value None Accept pipeline input? false Accept wildcard characters? false -Forward [<SwitchParameter>] Sends events for this subscription to the session on the local computer. Use this parameter when you are registering for events on a remote computer or in a remote session. Required? false Position? named Default value False Accept pipeline input? false Accept wildcard characters? false -MessageData <psobject> Specifies additional data associated with the event. The value of this parameter appears in the MessageData property of the event object. Required? false Position? named Default value None Accept pipeline input? false Accept wildcard characters? false -SourceIdentifier <string> Specifies the source identifier of the event to which you are subscribing. The source identifier must be unique in the current session. This parameter is required. The value of this parameter appears in the value of the SourceIdentifier property of the subscriber object and of all event objects associated with this subscription. Required? true Position? 101 Default value Accept pipeline input? false Accept wildcard characters? false -SupportEvent [<SwitchParameter>] Hides the event subscription. Use this parameter when the current subscription is part of a more complex event registration mechanism and it should not be discovered independently. To view or cancel a subscription that was created with the SupportEvent parameter, use the Force parameter of the Get-EventSubscriber and Unregister-Event cmdlets. Required? false Position? named Default value False Accept pipeline input? false Accept wildcard characters? false <CommonParameters> This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer and OutVariable. For more information, type, "get-help about_commonparameters".
INPUTS
None You cannot pipe input to Register-EngineEvent.
OUTPUTS
None or System.Management.Automation.PSEventJob If you use the Action parameter, Register-EngineEvent returns a System.Management.Automation.PSEventJob object. Otherwise, it does not generate any output.
NOTES
Events, event subscriptions, and the event queue exist only in the current session. If you close the current session, the event queue is discarded and the event subscription is canceled.

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 from 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 the event queue, use Remove-Event. 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 C:\Windows>powershell get-help Wait-Event -full

Microsoft Windows [Version 10.0.19045.3693]
Copyright (c) 2023 Microsoft Corporation.

ColorConsole [Version 3.7.1000] PowerShell 2.0-Export

Windows 11, 10, 8.1, 8, 7 / Server 2022, 2019, 2016











Windows-10


... Windows 10 FAQ
... Windows 10 How To


Windows 10 How To


... Windows 11 How To
... Windows 10 FAQ



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

HTTP: ... PS_Windows/en/Register-EngineEvent.htm
0.062
20518

Toolbar aktivieren bei Firefox, bitte um Hilfe?

How to make in Windows 8 or 8.1 a restart with recovery options?

Was ist phishing, fischen im Internet?

Help, can not customize the language on Samsung mobile phone with Android!

Clear virtual memory pagefile at Windows-8 Shutdown (8.1, 10, seven)!

Wie kann ich Windows 8.1, 10, 11 im abgesicherten Modus starten (booten)?



(0)