2016-09-26 1050 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值。