Author Posts

August 16, 2018 at 10:34 pm

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

August 17, 2018 at 12:00 am

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

August 20, 2018 at 7:42 pm

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?

August 20, 2018 at 9:46 pm

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.