Sort woes

Welcome Forums General PowerShell Q&A Sort woes

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
2 months, 3 weeks ago.

  • Author
    Posts
  • #108781

    Participant
    Points: 48
    Rank: Member

    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

  • #108803

    Participant
    Points: 135
    Helping Hand
    Rank: Participant

    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
  • #109085

    Participant
    Points: 48
    Rank: Member

    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?

    • #109106

      Participant
      Points: 135
      Helping Hand
      Rank: Participant

      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. 😀 But I'm glad it was helpful.

You must be logged in to reply to this topic.