title: powershell error-CategoryInfo : InvalidOperation: (split:String) [], RuntimeException
body: <pre><code>$Analog_File = "c:\temp\test\mt.txt"
  #(Get-Item $Analog_File).length
  if((Test-Path(-not $Analog_File)) -or ((Get-Item $Analog_File).length -eq 0kb))
  {
      exit
  }
  $m = Select-String -pattern  ",T" c:\temp\test\mt_1.txt
  #$m.length #Get the number of rows
  
  For ($i=0; $i -le $m.length; $i++)
  {
      $s1 = $m[$i] -split ":"
      $s1[2]
      if ([int]$s1[2] -ge 9)    #le = less than, ge = greater than, eq = equal to
      {
          $s2 = $s1[3] -split ","
          $compid = $s2[2].split('''')[0] + "." + $s2[3].split('''')[0] + "." + $s2[4].split('''')[0] + "." + $s2[5].split('''')[0]
          $matches = (Select-String -pattern  $compid c:\temp\test\mt_1.txt).line
          #($matches.split(';')[0]) 
          #($matches.split(';')[0]).split(',')[0]
          #($matches.split(';')[0]).split(',')[1]
          if ($s2[6] -eq "T")
          {
              #$s2[2].split('''')[1]
              #"Not in Service"
              #"!" + ($matches.split(';')[0]).split(',')[0] + "!" + ($matches.split(';')[0]).split(',')[1] + "!0!" &gt;&gt; $fname
          }
          if ($s2[7] -eq "T")
          {
              #"Alarm inhibit"
              #"!" + ($matches.split(';')[0]).split(',')[0] + "!" + ($matches.split(';')[0]).split(',')[1] + "!1!" &gt;&gt; $fname
          }
          if ($s2[8] -eq "T")
          {
              #"Manual update"
              #"!" + ($matches.split(';')[0]).split(',')[0] + "!" + ($matches.split(';')[0]).split(',')[1] + "!2!" &gt;&gt; $fname
          }
      }
  }
  </code></pre>
  
  <p>the error message:</p>
  
  <p>You cannot call a method on a null-valued expression.</p>
  
  <p>At line:17 char:31</p>
  
  <ul>
  <li><p>$compid = $s2[2].split &lt;&lt;&lt;&lt; ('''')[0] + "." + $s2[3].split('''')[0] + "." + $s2[4].split('''')[0] + "." + $s2[5].split('''')[0]</p>
  
  <ul>
  <li><p>CategoryInfo          : InvalidOperation: (split:String) [], RuntimeException</p></li>
  <li><p>FullyQualifiedErrorId : InvokeMethodOnNull</p></li>
  </ul></li>
  </ul>
  
  <p>what can i do??</p>