答案 0 :(得分:1)
以下是支持案例的正确答案,那么您有多个具有相同名称的进程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 :(得分:-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)
答案 2 :(得分:-1)
Get-Process -Name系统|选择CPU
获取2实例的cpu时间为(cpu2-cpu1)/(t2-t1)* 100。您将获得%的CPU值。