通过PowerShell获取系统健康信息


0

是否可以通过PowerShell获取系统健康状态?CPU利用率,使用的RAM,CPU温度等信息

Answers:


2

由于PowerShell可以创建.NET Framework对象,我建议使用PerformanceCounter类来完成此任务。

这个类可以很麻烦地使用,但提供了您需要的大多数功能。

对于类别列表,您只需调用静态GetCategories()方法即可获得:

[System.Diagnostics.PerformanceCounterCategory]::GetCategories()

为了帮助您入门,我写了一个小小的演示:

$pc_prc = new-object System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total")
$pc_ram = new-object System.Diagnostics.PerformanceCounter("Memory", "Available MBytes")

while(1) {
    $time = get-date
    echo ======================
    echo $time
    echo ======================
    $pc_prc_value = $pc_prc.NextValue()
    $pc_ram_value = $pc_ram.NextValue()
    echo " + Processor Load:   $pc_prc_value %"
    echo " + Available Memory: $pc_ram_value MB"
    sleep 1
}

请注意PerformanceCounter该类支持检索CPU温度数据,因为该过程高度依赖于体系结构。

有关更多信息,请查看此SO问题

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.