The PowerShell script gets all processes that are not 0 CPU usage in real time and merges the name-consistent processes.
#定义结果输出路径
$OutFile = "D:\CPU_" + (get-date). Getdatetimeformats () [1] + ". csv"
#定义性能收集器对象
$CpuCores = (Get-wmiobject win32_computersystem). NumberOfLogicalProcessors
$Processes = Get-counter "\process (*) \% Processor Time"
$Timestamp = $Processes. Timestamp
$Samples = $Processes. countersamples
#对相同进程进行叠加汇总
[Email protected] ()
$Process _group = $Samples | Group-object-property InstanceName
Foreach ($Group in $Process _group)
{
$TEMPOBJ = New-object PsObject
$Member = $Group. Group
$MemberName = $Group. Name
$Sum = ($Member | measure-property cookedvalue-sum). Sum
if ($sum-ne "0")
{
$Sumformat = "{0:n2}"-F ($sum)
$TEMPOBJ | Add-member-type noteproperty-name "Process"-value $MemberName
$TEMPOBJ | Add-member-type noteproperty-name "CPU%"-value $Sumformat
$TEMPOBJ | Add-member-type noteproperty-name "Timestamp"-value $Timestamp
$Process _poly + = $TEMPOBJ
}
}
#输出结果
$Process _poly | Export-csv-path $OutFile-encoding Utf8-force-notypeinformation-append
This article is from the "Essence of the" blog, please be sure to keep this source http://simy88.blog.51cto.com/7370552/1683840
PowerShell script gets all CPU usage time not 0 process in real time