title: Compare two column or more column in CSV and merge match data in new csv
body: <p>I have two CSV files and both have 2 common column (computer name and date).
  One CSV file has 5 columns and second CSV has 22 columns.</p>
  
  <p>I want to compare two column data (computer name &amp; date) with second CSV file and if it match then add one more column in CSV 1 (5 column) and insert data from different column.</p>
  
  <p>1st csv data</p>
  
  <pre><code>Computer Name   Creation time
  
  12301825        9/1/2013 1:23
  
  23304825        8/1/2013 1:23
  
  43307825        6/1/2013 1:23
  
  53308825        9/1/2013 1:23
  
  63305825        5/1/2013 1:45
  
  73305825        9/1/2013 1:45
  </code></pre>
  
  <p>2nd csv data</p>
  
  <pre><code>Computer Name   Creation time   Value
  
  12301825        9/1/2013 1:23   2
  
  27704825        8/1/2013 1:23   3
  
  43307825        6/1/2013 1:23   4
  
  53308825        9/1/2013 1:23   5
  
  63305825        5/1/2013 1:45   9
  
  73305825        9/1/2013 1:45   7
  </code></pre>
  
  <p>I want to compare both column in both csv file and if value match then merge value column in first csv file.</p>
  
  <p>I tried to start creating script but i don't know how it can be done in powershell.</p>
  
  <pre><code>$alert=Import-Csv -Path ".\alert.csv" -Header "Computer Name" | Sort-object Property "Computer Name" -Unique 
  $threat = Import-Csv ".\threat.csv" -Header "Computer Name" |Sort-Object -Property "Computer Name" -Unique
  Compare-Object $alert $threat -Property  "Computer Name" |  Where-Object{$_.SideIndicator -eq '=&gt;'} | 
      Select-Object  "Computer Name" | export-csv .\Difference.csv -NoTypeInfo
  </code></pre>
  
  <p>It is not a script which I want to create because it is not relevant with my requirement.</p>
  
  <h2>Update</h2>
  
  <p>alert.csv contain 22 column and threats.csv contain 5 column. I want to compare threats.csv with alert.csv.</p>
  
  <p>When I run below script I am getting output file like this.</p>
  
  <pre><code>$alert=Import-Csv -Path "d:\ps\alert.csv"
  $threat = Import-Csv -Path "d:\ps\threat.csv"
  ForEach($Record in $threat){
      $MatchedValue = (Compare-Object $alert $Record -Property "Computer Name","Creation time" -IncludeEqual -ExcludeDifferent -PassThru).value
      $Record = Add-Member -InputObject $Record -Type NoteProperty -Name "Values" -Value $MathedValue
  }
  $threat|Export-Csv "d:\ps\threatss.csv" -NoTypeInformation
  </code></pre>
  
  <p>Output in file data </p>
  
  <pre><code>PK!?z?b??[Content_Types].xml ??(??T?N?0?#???(q?!?G?|??7?U?????=??V?J???$?????{2?4.[CB|)??Hd?u0?/J?????Iy?\?P?-??M//&amp;o????R?D?NJ?54  Values
  "???*?F???J/???ht#u??rj1?t???5??U?g?0??8I??s\0???????*Fg?""V.???a?CUY
  &amp;?U?\Ev??   ???d*?  ???W?;????Q??az?8&lt;n?o3?????F`?n???!"    
  ????[=? 
  &amp;$???W?4?K??H"?xR??d?????N?9????Aw(7ey/???O??   
  ???h?????m?|    
  ?}D?g"$?4??F?Y??.2#???5?9????Y]b??d??@??%?s?"??0?tB??)???[??????????PK!?p??Hxl/workbook.xml?Q?N?0?#????I????TB??!Q??7?U?l????U  
  </code></pre>