title: Parsing powershell output
body: <p>I ran into such a problem, I don't know how best to solve it.
  We have this script, determining the load on the CPU.</p>
  <pre><code>$pc = 'cmd'
   
  try {$Connection = Test-Connection -ComputerName $pc -Count 2 -EA Stop}
  catch {Write-Host &quot;NO network connection to $PC&quot; -fo Red; break}
   
  try
  {
      $option = New-CimSessionOption -Protocol Dcom
      $session = New-CimSession -ComputerName $pc -SessionOption $option -EA Stop
  }
  catch
  {
      try
      {
          $option = New-CimSessionOption -Protocol Wsman
          $session = New-CimSession -ComputerName $pc -SessionOption $option -EA Stop
      }
      Catch {Write-Host &quot;NOT connect to CimSession on $PC&quot; -fo Red; break}
  }
   
  $ComputerSystem = Get-CimInstance -ClassName Win32_ComputerSystem -CimSession $session
  $CpuCores = $ComputerSystem.NumberOfLogicalProcessors
   
  Write-Host 'Please wait for CPU Usage data to be collect...' -fo Yellow
   
  if (Get-Counter -ListSet * -ComputerName $pc | ? Paths -Match &quot;\\Процесс\(\*\)&quot;){$CounterPath = &quot;\Процесс(*)\% загруженности процессора&quot;}
  else {$CounterPath = &quot;\Process(*)\% Processor Time&quot;}
   
  $CPU_Usage_Counter = (Get-Counter -Counter $CounterPath -SampleInterval 1 -MaxSamples 5 -ComputerName $pc -EA SilentlyContinue).CounterSamples | ? CookedValue -ne 0 | group InstanceName
   
  $CPU_Usage_Data = $CPU_Usage_Counter | select Name,@{N='CPU_Usage_%';E={[math]::Round(($_.Group | %{$_.CookedValue} | measure -Average).Average/$CpuCores,2)}}
  $CPU_Usage_Data | ? Name -ne '_total' | sort 'CPU_Usage_%' -Des | ft -a
   
  Write-Host &quot;NumberOfLogicalProcessors: $CpuCores&quot;
  $check = Write-Host &quot;CpuUsageProcess&quot; ( [math]::Round((100 - (($CPU_Usage_Data | ? Name -eq 'idle').'CPU_Usage_%')),2) ) -fo Yellow
  #####---------------------------------------------------------------------------------------------------------------------------------------------------
  
  $status = (($check).CpuUsageProcess -gt 5)
  if($status)
  {
      #Break
      Write-Host -ForegroundColor Green 'if!'
  }
  else
  {
      Write-Host -ForegroundColor Red 'else!'
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/6NcTQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6NcTQ.png" alt="enter image description here" /></a></p>
  <p>After execution, you need to extract the result of the &quot;CpuUsageProcess&quot; value and use it in the if / else condition</p>