# Sort woes

**URL:** <https://forums.powershell.org/t/sort-woes/11149>\
**Category:** PowerShell Help\
**Created:** [August 16, 2018, 5:04pm UTC](https://forums.powershell.org/t/sort-woes/11149 "2018-08-16T17:04:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [August 16, 2018, 5:04pm UTC](https://forums.powershell.org/t/sort-woes/11149/1 "2018-08-16T17:04:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 16, 2018, 6:30pm UTC](https://forums.powershell.org/t/sort-woes/11149/2 "2018-08-16T18:30:38Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [August 20, 2018, 2:12pm UTC](https://forums.powershell.org/t/sort-woes/11149/3 "2018-08-20T14:12:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 20, 2018, 4:16pm UTC](https://forums.powershell.org/t/sort-woes/11149/4 "2018-08-20T16:16:59Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/sort-woes/11149/5 "2024-05-16T20:34:30Z")

</div>


