Unregister-Event
取消事件订阅。
语法
BySource (默认值)
Unregister-Event
[-SourceIdentifier] <String>
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
ById
Unregister-Event
[-SubscriptionId] <Int32>
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
Unregister-Event cmdlet 取消使用 Register-EngineEvent、Register-ObjectEvent 或 Register-WmiEvent cmdlet 创建的事件订阅。
取消事件订阅后,事件订阅服务器将从会话中删除,并且订阅的事件不再添加到事件队列。 使用 New-Event cmdlet 取消对事件创建的订阅时,也会从会话中删除新事件。
Unregister-Event 不会从事件队列中删除事件。 若要删除事件,请使用 Remove-Event cmdlet。
示例
示例 1:按源标识符取消事件订阅
PS C:\> Unregister-Event -SourceIdentifier "ProcessStarted"
此命令取消具有 ProcessStarted 源标识符的事件订阅。
若要查找事件的源标识符,请使用 Get-Event cmdlet。 若要查找事件订阅的源标识符,请使用 Get-EventSubscriber cmdlet。
示例 2:按订阅标识符取消事件订阅
PS C:\> Unregister-Event -SubscriptionId 2
此命令取消订阅标识符为 2 的事件订阅。
若要查找事件订阅的订阅标识符,请使用 Get-EventSubscriber cmdlet。
示例 3:取消所有事件订阅
PS C:\> Get-EventSubscriber -Force | Unregister-Event -Force
此命令取消会话中的所有事件订阅。
该命令使用 Get-EventSubscriber cmdlet 获取会话中的所有事件订阅服务器对象,包括通过使用事件注册 cmdlet SupportEvent 参数隐藏的订阅服务器。
它使用管道运算符 (|) 将订阅服务器对象发送到 Unregister-Event,这会将其从会话中删除。 若要完成任务,Unregister-Event也需要 Force 参数。
参数
-Confirm
在运行 cmdlet 之前,提示你进行确认。
参数属性
| 类型: | SwitchParameter |
| 默认值: | False |
| 支持通配符: | False |
| 不显示: | False |
| 别名: | cf |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-Force
取消所有事件订阅,包括通过使用 Register-ObjectEvent的 SupportEvent 参数、Register-WmiEvent和 Register-EngineEvent隐藏的订阅。
参数属性
| 类型: | SwitchParameter |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-SourceIdentifier
指定此 cmdlet 取消事件订阅的源标识符。
必须在每个命令中包含 SourceIdentifier 或 SubscriptionId 参数。
参数属性
| 类型: | String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
BySource
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-SubscriptionId
指定此 cmdlet 取消事件订阅的源标识符 ID。
必须在每个命令中包含 SourceIdentifier 或 SubscriptionId 参数。
参数属性
| 类型: | Int32 |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
ById
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 命令脚本未运行。
参数属性
| 类型: | SwitchParameter |
| 默认值: | False |
| 支持通配符: | False |
| 不显示: | False |
| 别名: | 无线 |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters。
输入
PSEventSubscriber
可以通过管道将输出从 Get-EventSubscriber 传递给 Unregister-Event。
输出
None
此 cmdlet 不返回任何输出。
备注
事件、事件订阅和事件队列仅存在于当前会话中。 如果关闭当前会话,事件队列将被丢弃,事件订阅也将被取消。
Unregister-Event 无法删除使用 New-Event cmdlet 创建的事件,除非已使用 Register-EngineEvent cmdlet 订阅事件。 若要从会话中删除自定义事件,必须以编程方式删除该事件或关闭会话。