-3

I want to copy the csv files from two different servers and then paste those files at some location on 3rd server.

CSV File location on 1st server is - E:\HC_Disk\Sample\"+"DiskSpace-"+(Get-Date -format yyyyMMdd)+".csv

CSV file location on 2nd server - E:\HC_Disk\Sample\"+"DiskSpace-"+(Get-Date -format yyyyMMdd)+".csv

I have the script which generates the files everyday. My main concern is to club the two files together in the powershell.

Can you please help me with that. Thanks

Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
  • 1
    Is this a request to create a code for you or there is your code which is not working properly? If the latter, please share it – maoizm Apr 17 '18 at 01:23
  • I have not written any code for it so far. If you have any, please share it with me. Thanks! – Haninder Cheema Apr 17 '18 at 19:40
  • When I use the Robocopy command : robocopy \\ServerA\E:\HC_Disk\Sample\"+"DiskSpace-"+(Get-Date-format yyyyMMdd)+".csv\ \\ServerB\E:\Test\ I'll get the error as invalid parameter "-format". Could you please suggest on this? – Haninder Cheema Apr 17 '18 at 23:38

1 Answers1

0

If you're referring to merging two CSVs, assuming the same headers, try below (modify for your filenames/paths):

Get-Content file1.csv, file2.csv | Select-Object -Unique | Set-Content mergedfile.csv
bentek
  • 2,205
  • 1
  • 14
  • 23
  • Thanks for the answer. My headers are same in both the files. Also if I have to copy the above two files from two different servers to the 3rd server, how can we use ROBOCOPY for that? – Haninder Cheema Apr 17 '18 at 22:26
  • 1
    @HaninderCheema Have you made any effort at all to solve this yourself? – EBGreen Apr 18 '18 at 12:20
  • Copying files from one system to another system is a basic and thoroughly documented process that can be achieved using a plethora of methods, all of which can be found via Google. Combining the files after copying can be achieved using the code I posted above via PowerShell, or another method if you prefer. – bentek Apr 18 '18 at 19:07