Comparing two larger text arrays in PowerShell
<p>I have two arrays that I would like to take the difference between.  I had some success with COMPARE-OBJECT, but is too slow for larger arrays.  In this example $ALLVALUES and $ODD are my two arrays.</p>

<p>I used to be able to do this efficiently using FINDSTR
ex.  <strong>FINDSTR /V /G:ODD.txt ALLVALUES.txt > EVEN.txt</strong>  FINDSTR finished this in under 2 seconds for 110,000 elements. (even had to read and write from the disk) </p>

<p>I'm trying to get back to the FINDSTR performance where it would give me everything in ALLVALUES.txt that did NOT match ODD.txt (giving me the EVEN values in this case)  </p>

<p>NOTE: This question is not about ODD or EVEN, only a practical example that can be quickly and visually verified that it is working as desired.</p>

<p>Here is the code that I have been playing with. Using COMPARE-OBJECT, 100,000 took like 200 seconds vs 2 seconds for FINDSTR on my computer.  I'm thinking there is a much more elegant way to do this in <strong>PowerShell</strong>.  Thanks for your help.</p>

<pre><code># -------  Build the MAIN array
$MIN = 1
$MAX = 100000
$PREFIX = "AA"

$ALLVALUES = while ($MIN -le $MAX) 
{
   "$PREFIX{0:D6}" -f $MIN++
}


# -------  Build the ODD values from the MAIN array
$MIN = 1
$MAX = 100000
$PREFIX = "AA"

$ODD = while ($MIN -le $MAX) 
{
   If ($MIN%2) {
      "$PREFIX{0:D6}" -f $MIN++
   }
  ELSE {
    $MIN++
   }
}

Measure-Command{$EVEN = Compare-Object -DifferenceObject $ODD -ReferenceObject $ALLVALUES -PassThru}
</code></pre>