SOLVED

Ordering data in hash of hashes

Contributor

Hello,

 

I have this piece of code :

 

 

 

...
#Get GPOs with all settings disabled
    $GpoList |
        Where-Object {$_.gpostatus -eq "allsettingsdisabled"} |
            ForEach-Object{
                $CandidateGPOs[$_.id] = 
                    @{
                        ID                    = $_.id
                        DisplayName           = $_.displayname
                        CreationTime          = $_.creationtime
                        Modificationtime      = $_.modificationtime
                        Owner                 = $_.Owner
                        Domain                = $domain
                        All_Settings_Disabled = $CandidateGPOs[$_.id].All_Settings_Disabled +"True"
                        Not_linked            = $CandidateGPOs[$_.id].Not_linked +""
                        Links_disabled        = $CandidateGPOs[$_.id].Links_disabled +""
                        No_settings           = $CandidateGPOs[$_.id].No_settings +""
                     } 
}
... 
#other similar loops checking other settings (not linked, links disabled, no settings).
    
$candidateGPOs.GetEnumerator() | Sort-Object $_.keys | ForEach-Object{[PSCustomObject]$_.value } | Export-Csv "$ReportPath\_candidateGPOs_Listing.csv" -NoTypeInformation -Append -delimiter ";"

 

 

 

 

The result is not in the same order in the CSV.
The command give this order : $candidateGPOs.GetEnumerator() | Sort-Object $_.keys | ForEach-Object{[PSCustomObject]$_.value } =>
Modificationtime : 13.06.2019 11:24:02
ID : b17dfccad9c-a93c0-41a9-8d04-e119a549450f
CreationTime : 24.03.2007 14:27:45
No_settings : True
Domain : contoso.comt
Not_linked :
Owner : contoso\Domain Admins
All_Settings_Disabled :
Links_disabled :
DisplayName : Default Domain Controllers Policy

 

It was working before. I don't understand what I wrongly changed...

Thank you

 

O

3 Replies
best response confirmed by John_Dodo (Contributor)

@dotpwsh 
Thank you, but my problem is not about sorting the data but about sorting the columns for the output.

They do not come in the same order as the variable definition.

 

Before they were ordered as expected and suddenly it changed.

Actually it works. Thank you