Parsing through XML help

Welcome Forums General PowerShell Q&A Parsing through XML help

Viewing 2 reply threads
  • Author
    Posts
    • #184050
      Participant
      Topics: 17
      Replies: 22
      Points: 210
      Rank: Participant

      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.

    • #184161
      Participant
      Topics: 1
      Replies: 63
      Points: 355
      Helping Hand
      Rank: Contributor

      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

       

       

       

    • #184742
      Participant
      Topics: 10
      Replies: 117
      Points: 456
      Helping Hand
      Rank: Contributor

      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
      }
Viewing 2 reply threads
  • You must be logged in to reply to this topic.