如何设置包含动态条件的永久 WMI 订阅?

发布于 2025-01-16 16:01:34 字数 804 浏览 4 评论 0原文

我想创建一个永久的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文