Sort woes

I have this code:

Import-Module GroupPolicy
Get-GPO -All | 
    %{ 
       If ( $_ | Get-GPOReport -ReportType XML | Select-String -NotMatch "LinksTo" | sort -Property DisplayName )
        { 
         Write-Host $_.DisplayName 
        }
    }

…but I don’t get the sorting I desire…I want to sort alphabetically ascending and it’s all over the place with the first letter. I did a gm on Get-GPO and see displayName so chose that. Get-GPOReport only has methods.

Is my sort in the wrong position? I’m always confused with multiple curly braces as to where to put in sorts or Get-Member.

thanks

If I got you right you could start with something like this:

Get-GPOReport -All -ReportType xml |
ForEach-Object{
([xml]_).gpo | Select-Object -Property Name,@{Name='LinkedTo';Expression={.LinksTo | ForEach-Object {$.SOMName}}}
} |
Where-Object -Property LinkedTo |
Sort-Object -Property Name

That works great for finding (and sorting fully) all LINKED GPOs but I actually wanted the unlinked GPOs. Not seeing any kind of operator that might allow me to set an Is Not Equal to, i.e. in your revised code.

I wasn’t aware of ([xml]$_).gpo method of gathering the objects to sort. How do I discover more about that?

I wasn't aware of ([xml]$_).gpo method of gathering the objects to sort. How do I discover more about that?
Hmmm ... ;-) ... I have to admit I wasn't aware of that right away neither - I simply googled it. :-D But I'm glad it was helpful.