# powershell -noprofile Set-ExecutionPolicy Unrestricted# 如果程序运行失败,请以管理员运行CMD,执行第一段#号后面的命令!$counter=New-ObjectDiagnostics.PerformanceCounter$counter.CategoryName="Processor"$counter.CounterName="% Processor Time"$counter.InstanceName="_Total"while($true){$value=$counter.NextValue()$result="{0:N0}"-f$valueWrite-Host" CPU Utilization: $result%"Write-Host" Date: $(Get-date)"Write-Host$path=Split-Path-Parent$MyInvocation.MyCommand.DefinitionWrite-Output"CPU Utilization: $($result)%">>"$path\CPU Utilization.txt"Write-Output"Date: $(Get-date)">>"$path\CPU Utilization.txt"Write-Output"">>"$path\CPU Utilization.txt"Sleep5#修改Sleep的赋值,可以更改监控频率!}
运行界面: