title: Cannot index into a null array
body: <p>I am using a template that sets the cell color based on a condition if a server backup was successful or not.</p>
  
  <p>I have the below code which is continuously throwing the error: Cannot index into a null array:</p>
  
  <pre>
  Cannot index into a null array.
  At C:\Users\admin\Desktop\new.html.ps1:65 char:17
  + ...             $Value = $Search.Matches[$Index].Groups[1].Value -as [dou ...
  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
  </pre>
  
  <p>The final output still produces the correct results (colors etc), but how can I set the script to ignore any null values so I no longer receive these errors? I have tested with condition 'if ($Value -ne $null)' which works well, however no colors are shown on the cells.</p>
  
  <p>Code:</p>
  
  <pre><code>Process {
      foreach ($Line in $InputObject) {
          if ($Line.IndexOf("&lt;tr&gt;&lt;th") -ge 0) {
              Write-Verbose "$(Get-Date): Processing headers..."
              $Search = $Line | Select-String -Pattern '&lt;th ?[a-z\-:;"=]*&gt;(.*?)&lt;\/th&gt;' -AllMatches
              $Index = 0
              foreach ($Match in $Search.Matches) {
                  if ($Match.Groups[1].Value -eq $Property) {
                      break
                  }
                  $Index ++
              }
              if ($Index -eq $Search.Matches.Count) {
                  Write-Warning "$(Get-Date): Unable to locate property: $Property in table header"
                  exit
              }
              Write-Verbose "$(Get-Date): $Property column found at index: $Index"
          }
  
          if ($Line -match "&lt;tr( style=""background-color:.+?"")?&gt;&lt;td") {
              $Search = $Line | Select-String -Pattern '&lt;td ?[a-z\-:;"=]*&gt;(.*?)&lt;\/td&gt;' -AllMatches
              $Value = $Search.Matches[$Index].Groups[1].Value -as [double]
              if (-not $Value) {
                  $Value = $Search.Matches[$Index].Groups[1].Value
              }
              if (Invoke-Command $Filter) {
                  if ($Row) {
                      Write-Verbose "$(Get-Date): Criteria met!  Changing row to $Color..."
                      if ($Line -match "&lt;tr style=""background-color:(.+?)""&gt;") {
                          $Line = $Line -replace "&lt;tr style=""background-color:$($Matches[1])","&lt;tr style=""background-color:$Color"
                      } else {
                          $Line = $Line.Replace("&lt;tr&gt;","&lt;tr style=""background-color:$Color""&gt;")
                      }
                  } else {
                      Write-Verbose "$(Get-Date): Criteria met!  Changing cell to $Color..."
                      $Line = $Line.Replace($Search.Matches[$Index].Value,"&lt;td style=""background-color:$Color""&gt;$Value&lt;/td&gt;")
                  }
              }
          }         
          Write-Output $Line
      }
  }     
  End {
      Write-Verbose "$(Get-Date): Function Set-CellColor completed"
  }
  </code></pre>