Unregister-Event

Cancel an event subscription.

Syntax
      Unregister-Event [-SubscriptionId] int [-Force]
         [-Confirm] [-WhatIf] [CommonParameters]

      Unregister-Event [-SourceIdentifier] string [-Force]
         [-Confirm] [-WhatIf][CommonParameters]

Key:
   -SubscriptionId int
       Cancel event subscriptions that have the subscription identifier int.

   -SourceIdentifier string
       Cancel event subscriptions that have the source identifier string. 

   -Force
        Cancel all event subscriptions, including subscriptions that were hidden by using the SupportEvent
        parameter of Register-ObjectEvent, Register-WmiEvent, and Register-EngineEvent.

   -Confirm
       Prompt for confirmation before executing the command.

   -WhatIf
       Describes what would happen if you executed the command
       without actually executing the command.

Unregister-Event cancels an event subscription that was created by using the Register-EngineEvent, Register-ObjectEvent, or Register-WmiEvent cmdlet.

When an event subscription is canceled, the event subscriber is deleted from the session and the subscribed events are no longer added to the event queue. When a subscription to an event created with New-Event is cancelled, the new event is also deleted from the session.

Unregister-Event does not delete events from the event queue. To delete events, use Remove-Event

Examples

Cancel the event subscription with a source identifier of "ProcessStarted":

PS C:\> unregister-event -sourceIdentifier ProcessStarted

Cancel all event subscriptions in the session:

PS C:\> Get-EventSubscriber -force | unregister-event -force

Remove an event monitor SS64EventMonitor previously setup with Register-CimIndicationEvent:

PS C:\> Get-EventSubscriber -SourceIdentifier SS64EventMonitor | Unregister-Event

To also clear out the queue itself:

PS C:\> Get-Event -SourceIdentifier SS64EventMonitor | Remove-Event

“The fact that people find it easier to click “spam” than find your tiny, impossible-to-read, grey-text-on-white-background, stuck-inside-all-the-fine-print unsubscribe link is your own damn fault” ~ David Heinemeier Hansson

Related PowerShell Cmdlets

New-Event - Create a new event.
Get-Event - Get events in the event queue.
Remove-Event - Delete events from the event queue.
Register-CimIndicationEvent - Subscribe to indications using a filter or query expression.


 
Copyright © 1999-2024 SS64.com
Some rights reserved