title: Select-String sometimes results in "System.Object[]"
body: <p>I'm working on a script that combines parts of two text files.  These files are not too large (about 2000 lines each).
  I'm seeing strange output from select-string that I don't think should be there.
  Here's samples of my two files:</p>
  
  <p><strong>CC.csv - 2026 lines</strong></p>
  
  <pre><code>LS126L47L6/1L2#519,07448,1,B
  LS126L47L6/1R1-1#503,07449,1,B
  LS126L47L6/1L3#536,07450,1,B
  LS126L47L6/2R1#515,07451,1,B
  LS126L47L6/10#525,07452,1,B
  LS126L47L6/1L4#538,07453,1,B
  </code></pre>
  
  <p><strong>GI.txt - 1995 lines</strong></p>
  
  <pre><code>07445,B,SH,1
  07446,B,SH,1
  07448,B,SH,1
  07449,B,SH,1
  07450,B,SH,1
  07451,B,SH,1
  07452,B,SH,1
  07453,B,SH,1
  07454,B,SH,1
  </code></pre>
  
  <p>And here's a sample of the output file:</p>
  
  <p><strong>output in myfile.csv</strong></p>
  
  <pre><code> LS126L47L6/3R1#516,07446,1,B
   LS126L47L6/1L2#519,07448,1,B
   LS126L47L6/1R1-1#503,07449,1,B
   System.Object[],B
   LS126L47L6/2R1#515,07451,1,B
  </code></pre>
  
  <p>This is the script I'm using:</p>
  
  <pre><code>sc ./myfile.csv "col1,col2,col3,col4"
  
  $mn = gc cc.csv | select -skip 1 |  % {$_.tostring().split(",")[1]}
  $mn | % {
          $a = (gc cc.csv | sls $_ ).tostring() -replace ",[a-z]$", ""
          if (gc GI.txt | sls $_ | select -first 1)
              {$b = (gc GI.txt | sls $_ | select -first 1).tostring().split(",")[1]}
          else {$b = "NULL"
                  write-host "$_ is not present in GI file"}
          $c = $a + ',' + $b
          ac ./myfile.csv -value $c
          }
  </code></pre>
  
  <p>The $a variable is where I am sometimes seeing the returned string as <strong>System.Object[]</strong>
  Any ideas why?  Also, this script takes quite some time to finish.  Any tips for a newb on how to speed it up?</p>
  
  <p>Edit: I should add that I've taken one line from the cc.csv file, saved in a new text file, and run through the script in console up through assigning $a.  I can't get it to return "system.object[]".</p>
  
  <p>Edit 2:  After follow the advice below and trying a couple of things I've noticed that if I run </p>
  
  <p><code>$mn | %{(gc cc.csv | sls $_).tostring()}</code>   </p>
  
  <p>I get System.Object[].<br>
  But if I run</p>
  
  <p><code>$mn | %{(gc cc.csv | sls $_)} | %{$_.tostring()}</code>  </p>
  
  <p>It comes out fine. Go figure.</p>