title: Powershell to match lines in one file to part of a line in another.
body: <p>So I have two files, one with a list of numbers and a description, the other with just a list of numbers. </p>
  
  <p>Eg:<br>
  File 1 contains:  </p>
  
  <pre><code>10001 Screw  
  23456 Bolt
  </code></pre>
  
  <p>File2 contains:  </p>
  
  <pre><code>10001  
  23456  
  23456  
  </code></pre>
  
  <p>What I'm trying to do is for every time the number appears in File2 it adds the description to it or outputs the number and description to a new file.<br>
  So result would look like:  </p>
  
  <pre><code>10001 Screw  
  23456 Bolt  
  23456 Bolt 
  </code></pre>
  
  <p>These are just small samples but the actual files are many thousands of lines.</p>
  
  <p>This is what I've come up with but it's not quite right.</p>
  
  <pre><code>$file1 = "C:\pstest\file1.txt"
  $file2 = "C:\pstest\file2.txt"
  
  Get-Content $file2 | Foreach-Object -process {Get-Content $file1 | Where-Object  $_ -contains $file2 | write-host $_ }
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>$file1 = "C:\pstest\file1.txt"
  $file2 = "C:\pstest\file2.txt"
  $file3 = "C:\pstest\file3.txt"
  
  Get-Content $file2
  
  foreach ($line in $file2){
      Get-Content $file1 | Where-Object $_ -contains $line | out-file $file3 
  }
  </code></pre>