在 PowerShell 中向 WMI 发送 Refresh()

发布于 2024-08-24 15:21:23 字数 232 浏览 4 评论 0原文

在 PowerShell 脚本中,我尝试使用此命令获取每秒页面错误数:

(Get-WmiObject Win32_PerfFormattedData_PerfOS_memory).PageFaultsPersec

不幸的是,它总是读取相同的值,因为我没有 Refresh() 性能计数器。

如何通过 PowerShell 将 Refresh() 方法发送到性能数据?

In a PowerShell script I am trying to get the number of page faults per second with this command:

(Get-WmiObject Win32_PerfFormattedData_PerfOS_memory).PageFaultsPersec

Unfortunately, it reads always the same value because I don't Refresh() the performance counter.

How can I send a Refresh() method to Performance Data via PowerShell?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

装迷糊 2024-08-31 15:21:23

您可以使用性能计数器获取该值:

Get-Counter '\Memory\Page Faults/sec'

但是,如果我在循环中调用您的代码,它可以正常工作(尽管最好首先存储 wmi 对象)。

1..10 | % { sleep -sec 2; (Get-WmiObject Win32_PerfFormattedData_PerfOS_memory).PageFaultsPersec }

You can get the value using performance counters:

Get-Counter '\Memory\Page Faults/sec'

However, if I call you code in a loop, it works without problems (although it is better practise to first store the wmi object).

1..10 | % { sleep -sec 2; (Get-WmiObject Win32_PerfFormattedData_PerfOS_memory).PageFaultsPersec }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文