Unable to Extract data with my Hash

Mike 246 Reputation points
2022-09-14T12:35:34.487+00:00

I currently have a raw data that I wanted to clean. I am importing another CSV to look into this and remove anything that can be found. Finally export the final CSV.

RAWdata.csv contents
DisplayName,ObjectGUID
Michael,982c269f-39e2-4ae9-88d1-b6f804b2b763

Refernce.CSV
DisplayName,ObjectGUID
Michael,982c269f-39e2-4ae9-88d1-b6f804b2b763

$User = Import-Csv RawData.csv
$Reference = Import-Csv Reference.csv
$dataset = @{}
$Reference | foreach-object {
$dataset[$.DisplayName] = $.DisplayName}
$User | foreach-object { if (-not $dataset.containskey($.DisplayName)){
$

}
} | export-csv NewUser.csv -notypeinformation -encoding UTF8

-This Works

But changing it to $.ObjectGUID doesn't work.
$User = Import-Csv RawData.csv
$Reference = Import-Csv Reference.csv
$dataset = @{}
$Reference | foreach-object {
$dataset[$
.ObjectGUID] = $.ObjectGUID}
$User | foreach-object { if (-not $dataset.containskey($
.ObjectGUID)){
$_
}
} | export-csv NewUser.csv -notypeinformation -encoding UTF8

I am lost why it doesn't work.
Appreciate some help.

Not sure as well why "_" doesn't appear when I post here.

Thank you.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,504 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 46,551 Reputation points
    2022-09-14T15:08:28.733+00:00

    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


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.