Powershell Compare-Object Format Output
Something like this, maybe?
function compareCSV {$file1 = Read-Host "Please enter the path of the first file you would like to compare"$file2 = Read-Host "Please enter the path of the second file you would like to compare"$outFile1 = Read-Host "Please enter the path to where you would like your output file."Try{ $compareOne = Get-Content $file1 $comparetwo = Get-Content $file2} Catch{ Write-Host "The path you entered is either invalid or the file does not exist. " }Write-Host "Beginning comparison"$Compare = Compare-Object $compareOne $compareTwo$compare | foreach { if ($_.sideindicator -eq '<=') {$_.sideindicator = $file1} if ($_.sideindicator -eq '=>') {$_.sideindicator = $file2} } $Compare | select @{l='Value';e={$_.InputObject}},@{l='File';e={$_.SideIndicator}} | Out-File $outFile1 Write-Host "Complete!"}compareCSV
change this:
Compare-Object $compareOne $compareTwo | Out-File $outFile
with this:
Compare-Object $compareOne $compareTwo | ft inputobject, @{n="file";e={ if ($_.SideIndicator -eq '=>') { "$file2" } else { "$file1" } }} | Out-File $outFile