They should both work.
$User = Import-Csv c:\junk\RawData.csv
$Reference = Import-Csv c:\junk\Reference.csv
$dataset = @{}
# comparison by GUID
$Reference |
ForEach-Object {
$dataset[$_.ObjectGUID] = $_.ObjectGUID
}
$User |
ForEach-Object {
if (-not $dataset.containskey($_.ObjectGUID)) {
$_
}
} | Export-Csv c:\junk\NewUserByGUID.csv -NoTypeInformation -Encoding UTF8
# Comparison by name
$dataset = @{}
$Reference |
ForEach-Object {
$dataset[$_.DisplayName] = $_.DisplayName
}
$User |
ForEach-Object {
if (-not $dataset.containskey($_.DisplayName)) {
$_
}
} | Export-Csv c:\junk\NewUserByName.csv -NoTypeInformation -Encoding UTF8
The reason you lose the "_" is that you're not using the "Code Sample" editor when you post your code. The "normal" editor does strange and wonderful (NOT!) things to code.
The Code Sample editor is the 5th from the left on the Format Bar. It has a graphic the looks like this: 101 010