PowerShell script gets all CPU usage time not 0 process in real time

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.