Powershell获取CPU百分比 [英] Powershell Get CPU Percentage

查看:95
本文介绍了Powershell获取CPU百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何在Powershell中获取进程的CPU百分比似乎没有任何简单的解释。我已经用Google搜索并在这里搜索了,但没有发现任何确定的内容。有人可以通俗易懂地解释如何获得进程的CPU百分比吗?谢谢!

There doesn't seem to be any simple explanations on how to get CPU Percentage for a process in Powershell. I've googled it and searched here and I'm not seeing anything definitive. Can somebody explain in layman terms how to get CPU Percentage for a process? Thanks!

以下是一些让您入门的东西;)

Here's something to get you started ;)

$id4u = gps | ? {$_.id -eq 412}
function get_cpu_percentage {
# Do something cool here
}
get_cpu_percentage $id4u


推荐答案

使用WMI:

get-wmiobject Win32_PerfFormattedData_PerfProc_Process | ? { $_.name -eq 'powershell' } | select name,  PercentProcessorTime

功能:

    function get_cpu_percentage ($id )
{
(get-wmiobject Win32_PerfFormattedData_PerfProc_Process | ? { $_.idprocess -eq $id.id }).PercentProcessorTime
}

$id4u = gps | ? {$_.id -eq 412}
get_cpu_percentage -id $id4u

这篇关于Powershell获取CPU百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆