如何设置包含动态条件的永久 WMI 订阅?
我想创建一个永久的 WMI 订阅,以便在每次触发定义的触发器时启动脚本。在这里,我想在 Citrix RTT 高于给定阈值时做出反应。这里是获取 RTT 数据的常规 PS 代码示例(在第 2 行中使用过滤器):
$sid = [System.Diagnostics.Process]::GetCurrentProcess().SessionId
$rtt = Get-WmiObject -Namespace 'Root\Citrix\EUEM' -Class 'Citrix_Euem_RoundTrip' -Filter "SessionID=$sid"
现在,当我想要定义永久 WMI 订阅时,我正在努力设置正确的过滤条件,如上面的代码所示。这里是过滤器的示例:
$filter = [wmiclass]"root\subscription:__EventFilter"
$f1 = $filter.CreateInstance()
$f1.Name = "CitrixEvent"
$f1.EventNamespace = "root\Citrix\EUEM"
$f1.QueryLanguage = "WQL"
$f1.Query = "SELECT * FROM __InstanceModificationEvent WITHIN 10 WHERE TargetInstance ISA ""Citrix_Euem_RoundTrip"" GROUP WITHIN 10"
[void]$f1.Put()
这里的问题是,我不知道如何按正确的 SessionID 进行过滤。使用 WQL 语法可以实现这一点吗?我不想对与不同会话相关的事件做出反应。
I want to create a permanent WMI subscription to start a script every time a defined trigger gets fired. Here I would like to react when the Citrix RTT is above a given threshold. Here a regular PS-code sample to get that RTT data (with a filter in line 2):
$sid = [System.Diagnostics.Process]::GetCurrentProcess().SessionId
$rtt = Get-WmiObject -Namespace 'Root\Citrix\EUEM' -Class 'Citrix_Euem_RoundTrip' -Filter "SessionID=$sid"
Now when I want to define a permanent WMI subscription I am struggling to setup the correct filter-condition like shown in the above code. Here a sample for a filter:
$filter = [wmiclass]"root\subscription:__EventFilter"
$f1 = $filter.CreateInstance()
$f1.Name = "CitrixEvent"
$f1.EventNamespace = "root\Citrix\EUEM"
$f1.QueryLanguage = "WQL"
$f1.Query = "SELECT * FROM __InstanceModificationEvent WITHIN 10 WHERE TargetInstance ISA ""Citrix_Euem_RoundTrip"" GROUP WITHIN 10"
[void]$f1.Put()
Problem here is, that I dont know how to filter by the correct SessionID. Is that possible at all with the WQL-syntax? I do not want to react on an event which is related to a different session.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论