Parsing through XML help

I’m trying to create a report of all linked group policy objects.

I found this command which works for a single GPO

[XML]$GroupPolicy = Get-GPOReport -Name GPOName -ReportType XML
$GroupPolicy.GPO.LinksTo.SOMPath

If I change the command to Get-GPOReport -All it lists nothing.

This command Get-GPOReport -All Type XML does put all the info I need into an XML I’m just not sure how to parse it and pull out what I need.

What do you see if you type in

$grouppolicy

Something like:

xml GPOS


version=“1.0” encoding=“utf-16” GPOS

 

What if you then type in

$grouppolicy.gpos

something like:

GPO

and if you type in

$grouppolicy.gpos.gpo

 

You could also try:

$grouppolicy|get-member

 

 

 

This command Get-GPOReport -All Type XML does put all the info I need into an XML I'm just not sure how to parse it and pull out what I need.
So, what info do you need from the XML?

Regardless of what you need, you can loop through all GPOs then get the report for each one using Get-GPOReport -Name abc, instead of using Get-GPOReport -All. From your example code, here’s how it would work:

$allGPOs = Get-GPO -All

foreach ($gpo in $allGPOs) {

    [xml]$gpoReport = Get-GPOReport -Name $gpo.DisplayName -ReportType Xml

    # Output the SOMPath object
    $gpoReport.GPO.LinksTo.SOMPath
}