2016-09-26 25 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

は、同じ名前を持つ複数のprocesss 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

のGet-プロセス-Nameシステムを持ってサポートケースで正しい答えがありますCPUを選択

(cpu2-cpu1)/(t2-t1)* 100の2つのインスタンスでCPU時間を取得します。あなたは%でCPU値を取得します。

関連する問題