title: Inconsistent powershell script
body: <p>I am using a script that performs a basic health check on average CPU and Memory Utilization and checks if a specific service is running or not. The output will be displayed as HTML. If the CPU/Memory utilization is greater than 89%, or if ther service is not running, the affected server will be displayed in red. The script works just fine except for some inconsistencies that the server, even when under utilized, will be in red.</p>
  
  <p>Here is the powershell script I am using:</p>
  
  <pre><code>$ServerListFile = "C:\Scripts\HealthCheck\ServerList.txt"
  $ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue
  $Date = Get-Date -Format M.d.yyyy
  $Result = @()
  
  foreach ($computername in $ServerList) {
  
      $AVGProc = Get-WmiObject -ComputerName $computername Win32_Processor |
          Measure-Object -Property LoadPercentage -Average |
          Select-Object Average
      $OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computername |
          Select-Object @{Name = "MemoryUsage"; Expression = {"{0:N2}" -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
      $Service1 = Get-Service -ComputerName $computername -Name Service1
      $Service2 = Get-Service -ComputerName $computername -Name Service2
  
      $Result += [PSCustomObject] @{  
          ServerName = "$computername" 
          CPULoad    = "$($AVGProc.Average)%" 
          MemLoad    = "$($OS.MemoryUsage)%"
          Service1   = "$($Service1.Status)" 
          Service2   = "$($Service2.Status)"
      }
  
      $Outputreport = "&lt;HTML&gt;&lt;TITLE&gt; Server Health Check &lt;/TITLE&gt; 
                       &lt;BODY background-color:peachpuff&gt; 
                       &lt;font color =""#99000"" face=""Microsoft Tai le""&gt; 
                       &lt;H2&gt; Server Health Check &lt;/H2&gt;&lt;/font&gt; 
                       &lt;Table border=1 cellpadding=7 cellspacing=0&gt; 
               &lt;font face=""Calibri""&gt;
                       &lt;TR bgcolor=white align=center&gt; 
                         &lt;TD&gt;&lt;B&gt; Server Name &lt;/B&gt;&lt;/TD&gt; 
                         &lt;TD&gt;&lt;B&gt; Avrg.CPU  &lt;/B&gt;&lt;/TD&gt; 
                         &lt;TD&gt;&lt;B&gt; Memory  &lt;/B&gt;&lt;/TD&gt;
                     &lt;TD&gt;&lt;B&gt; Service1 &lt;/B&gt;&lt;/TD&gt;
                         &lt;TD&gt;&lt;B&gt; Service2&lt;/B&gt;&lt;/TD&gt;&lt;/TR&gt;"
  
      foreach ($Entry in $Result) {
          if (($Entry.MemLoad -gt "89") -Or ($Entry.CPULoad -gt "89") -or ($Entry.Service1 -eq "Stopped") -or ($Entry.Service2 -eq "Stopped")) {
              $Outputreport += "&lt;TR bgcolor=red&gt;"
          } else { 
              $Outputreport += "&lt;TR bgcolor=lightgreen&gt;"
          }
          $Outputreport += "&lt;TD&gt;$($Entry.Servername)&lt;/TD&gt;&lt;TD align=center&gt;$($Entry.CPULoad)&lt;/TD&gt;&lt;TD align=center&gt;$($Entry.MemLoad)&lt;/TD&gt;&lt;TD align=center&gt;$($Entry.Service1)&lt;/TD&gt;&lt;TD align=center&gt;$($Entry.Service2)&lt;/TD&gt;&lt;/TR&gt;" 
      }
  
      $Outputreport += "&lt;/Table&gt;&lt;/BODY&gt;&lt;/HTML&gt;"
  }
  
  $Outputreport | Out-File C:\Scripts\HealthCheck\ServerHealthCheck\HealthCheck_$Date.htm
  </code></pre>
  
  <p>Thanks!</p>