2016-09-26 1051 views
0

我想使用powershell命令获取特定进程的CPU使用率%(非处理器时间)。使用powershell获取特定进程的CPU%

例如:(Windows 8的任务管理器) enter image description here

我想这2.9%的命令。

+0

请参阅[如何在PowerShell脚本中获取特定进程的CPU使用率和内存消耗](https://stackoverflow.com/a/34844682) – wOxxOm

+0

'Get-Process'给出进程使用的处理器时间量在所有处理器上,我不相信这是CPU使用率% – galahad

+0

我的不好。我只是在看第一个答案。得到它了。谢谢 – galahad

回答

-1
Get-Process -Name PowerShell | Select CPU 

这是你要找的吗? 或更多的监测基础?

param 
(
    [String] 
    [Parameter(Mandatory)] 
    $Title 
) 

do 
{ 
    $process = Get-Process -Name $Title 
    $process 
    Start-Sleep -Seconds 1 
} while ($process) 
+0

'Get-Process'给出了进程拥有的处理器时间量在所有处理器上使用,我不是在寻找这个。我想要CPU使用率%。 – galahad

0

这是正确的答案是支持的情况下,那么你必须用相同的名字https://stackoverflow.com/a/34844682/483997

# To get the PID of the process (this will give you the first occurrance if multiple matches) 
$proc_pid = (get-process "slack").Id[0] 

# To match the CPU usage to for example Process Explorer you need to divide by the number of cores 
$cpu_cores = (Get-WMIObject Win32_ComputerSystem).NumberOfLogicalProcessors 

# This is to find the exact counter path, as you might have multiple processes with the same name 
$proc_path = ((Get-Counter "\Process(*)\ID Process").CounterSamples | ? {$_.RawValue -eq $proc_pid}).Path 

# We now get the CPU percentage 
$prod_percentage_cpu = [Math]::Round(((Get-Counter ($proc_path -replace "\\id process$","\% Processor Time")).CounterSamples.CookedValue)/$cpu_cores) 
-1

获取进程-Name系统中的多个PROCESSS |选择CPU

以(cpu2-cpu1)/(t2-t1)* 100获取2实例的CPU时间。你会得到%的CPU值。