Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Help with CSV Output

$
0
0

I am trying to cobble together a script to compare two CSV files and output the difference to a third CSV.  So far it does show me the difference between the two files, but my Output file is not in the correct format.  It does not give me the header row, and it places all output into one cell.

From what I understand, when it compares the two files, it reads all three of my columns as one object.  This does give me the correct output in all of my tests as some users have the same name, but different ID Number. 

Now I just need to Export my results to CSV in a more friendly format.  From what I have read I need to use a CustomPSObject, but my attempts have all failed miserably.

Here is my current code.

$path         = Split-Path -parent $MyInvocation.MyCommand.Definition
$newfile      = $path + "\a.csv"
$oldfile      = $path + "\b.csv"
$diffile      = $path + "\c.csv"

Compare-Object -ReferenceObject (get-content $oldfile) -DifferenceObject (Get-Content $newfile) | Where-Object {$_.SideIndicator -eq "=>"} | Export-CSV $diffile

 

Thanks for any help.

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles