title: how to get load per cores or processor using powershell scripting?
body: <p>I have written the following script for Windows Server 2012 &amp; Windows 7 that displays load per processor by using <code>Get-WmiObject -Class Win32_PerfFormattedData_PerfOS_Processor</code>. It is running quite well and also displays the load on console but when I keep checking the console outputs with performance monitor (% processor time), it is not matching with the console output. Is my script for checking the load per processor correct? How can I summarize my script with performance monitor?</p>
  
  <pre><code>while(1)
  {
  $cpucores = get-wmiobject win32_perfformatteddata_perfos_processor 
  $currenttime = get-date | out-file report.txt -append 
  write-host
  write-host "CPU Cores individually usage Monitoring"
  write-host  $currenttime
  for ($i=0; $i -lt $cpucores.count ; $i++) 
      {
      if($i -eq $cpucores.count-1) 
      {
      #write-host 
      $value=$cpucores[$i].percentprocessortime
      write-host "Total CPU " $value"% usage" 
      write-output "Total CPU  $value % usage" &gt;&gt; report.txt 
      write-output "..............................................................." &gt;&gt; report.txt
  
          }
      else
          {
          $load_value=[double]$cpucores[$i].percentprocessortime
          write-host "CPU Core"$i $load_value  "% usage"  -foregroundcolor green 
          write-output "CPU Core $i   $load_value %  usage" &gt;&gt; report.txt
  
          }
    }
    start-sleep -seconds 1
  
   }
  </code></pre>