TEXT

Monday, December 28, 2020

Merge CSV files by using PowerShell

  

Merge CSV files by using PowerShell

In the example below we will merge two CSV files into single CSV file bu using PowerShell. You can use same lines listed below and combine as many as CSV file you like. New CSV file will only contain unique values. Here is goes, as usual change some of the vars listed below to make it fit into your scenario

 

 

#(1)_.Path for CSV Files that needs to be comppared

$File1 = "C:\Users\12024\OneDrive - wiretecpro\Desktop\Compare-CSV\Data1-Computers.csv"

$File2 = "C:\Users\12024\OneDrive - wiretecpro\Desktop\Compare-CSV\Data2-Computers.csv"

 

#(2)_.Import CSV Files

$CSV1 = Import-Csv $File1

$CSV2 = Import-Csv $File2

 

#(3)_.Combine values to Single VAR

$mergedCSV = $csv1 + $csv2

 

#(4)_.Show Combined records

$mergedCSV | Select -Property * -Unique

 

#(5)_.EXPORT Combined FILES

$ExportFile = "C:\Users\12024\OneDrive - wiretecpro\Desktop\Compare-CSV\Combined.CSV"

$mergedCSV | Export-Csv -Path $ExportCSV

 

 

 

Casey, Dedeal

Azure Solutions Architect

AWS Certified Cloud Practitioner

 

https://simplepowershell.blogspot.com

 

https://cloudsec365.blogspot.com

 

https://msazure365.blogspot.com

 

https://twitter.com/Message_Talk

 

 


No comments:

Post a Comment

Simple Function Do Something

   Use template below to create simple PS function    # Simple Function Do Something # Change $ReportName   function Fu...