$files = '\\folder\FixedFQDNList.csv', '\\folder\MergeThisDomain.csv'
$doc2 = Import-Csv $files[1]|select -Property @{label="Indicator";expression=
{$($_."domain")}},@{label="Attribute::Admin Name";expression={$($_."admin contact
name")}},@{label="Attribute::Admin Organization"}}
$doc1 = Import-Csv $files[0]
$doc2OnlyColNames = (
Compare-Object $doc1[0].psobject.properties.name $doc2[0].psobject.properties.name |
Where-Object SideIndicator -eq '=>'
).InputObject
$htUniqueRowD2Props = [ordered] @{}
$recCnt = 1 # sets record count to 1 for displaying the number of domains
$i = 0 # sets the loop count to 0 for starting the foreach record search
$(foreach($rowD1 in $doc1) {
foreach($row2 in $doc2) {
if ($rowD1.Indicator -eq $row2.Indicator){
$rowD2 = $doc2[$i++]
foreach($pname in $doc2OnlyColNames) {$htUniqueRowD2Props.$pname = $rowD2.$pname}
$rowD1 | Add-Member -NotePropertyMembers $htUniqueRowD2Props -PassThru
}
}
$recCnt++
}) | Export-Csv -NoTypeInformation -Encoding Utf8 $outFile
What I am trying to do is compare 2 CSV files that have a common column (Indicator) and create a 3rd file called csvMerged.csv. If the indicator (domain) matches from the 2nd file to the first file, then append the additional columns, otherwise copy only the columns from the 1st file to the new file.
PROBLEM: I can get the new file (csvMerged) to add all of the domains with the additional details combined, but the domains that do not match are being skipped.
File 1: Full list of domains Indicator | ...Plus 8 more columns | | --------- | -------- | google.com | .... | yahoo.com | .... |
msn.com | .... |File 2: List of enhanced domains domain | ...Plus many more columns | | -------- | -------- | google.com | .... | msn.com | .... |
File 3: Combined List of domain details domain | ...Plus many more columns | | -------- | -------- | google.com | .... | msn.com | .... |
In the case above, the output (file 3) will show ONLY Google and MSN, NOT Yahoo.