{"id":4202,"date":"2013-02-07T00:01:00","date_gmt":"2013-02-07T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/02\/07\/use-powershell-to-generate-and-parse-a-group-policy-object-report\/"},"modified":"2013-02-07T00:01:00","modified_gmt":"2013-02-07T00:01:00","slug":"use-powershell-to-generate-and-parse-a-group-policy-object-report","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-generate-and-parse-a-group-policy-object-report\/","title":{"rendered":"Use PowerShell to Generate and Parse a Group Policy Object Report"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary:<\/strong><span style=\"font-size: 12px\"> Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to generate and parse a Group Policy Object report.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. So, I am working on my MCSE: Server Infrastructure certification and having passed the Installing and Configuring Windows Server 2012 exam (70-410), I am now studying for the Administering Windows Server 2012 exam (70-411). According to the <a href=\"http:\/\/www.microsoft.com\/learning\/en\/us\/exam.aspx?ID=70-411\" target=\"_blank\">70-411 exam guidelines<\/a>, 15 to 20 percent of the exam is related to Configuring and Managing Group Policy.<\/p>\n<p><strong>Note<\/strong> &nbsp;&nbsp;I have been taking Microsoft Certification exams since my first MCSE (on Windows&nbsp;NT 3.51). The one big tip I can give you is to adhere to the <em>Skills Being Measured (study guide). <\/em>If you see something on the list that you do not understand, look it up on TechNet, search the online Help, and actually perform the task. Luckily, now with Hyper-V, this is much easier. You can learn a lot by clicking through a wizard&mdash;much more than just looking at screenshots.<\/p>\n<p>Anyway, I am spending a lot of time here lately playing around with Group Policy.<\/p>\n<h2>Generating a RSOP report<\/h2>\n<p>Nearly everyone who has spent any time as a network administrator, or even a Help desk person, has run into situations that demand analyzing Resultant Set of Policy (RSoP). The dreaded situation arises where it seems settings are not being applied that should be applied or settings are applied that should not be applied. The standard tool for troubleshooting this is the GPRESULT command. The syntax of this command always seems a bit confusing, but eventually, I come up with a command that works. This command is shown here.<\/p>\n<p style=\"padding-left: 30px\">gpresult \/r<\/p>\n<p>Outputting the RSoP report to the Windows PowerShell console does not make for a great troubleshooting experience&mdash;everything goes to the console, and this results in a lot of scrolling up and down. This is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0081.hsg-2-7-13-01.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0081.hsg-2-7-13-01.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>One thing that can be done to improve this experience is to output the report to <strong>Out-GridView<\/strong>. This is shown here.<\/p>\n<p style=\"padding-left: 30px\">gpresult \/r | Out-GridView<\/p>\n<p>Even though the output is just plain text, it does not preclude using the <strong>Out-GridView<\/strong> cmdlet to parse the results.<\/p>\n<p>By typing in the filter box on top of the <strong>GridView<\/strong> pane, I can filter the text that appears in the bottom. This is a good way to bring some measure of control to the output.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1067.hsg-2-7-13-02.png\"><img decoding=\"async\" title=\"Image of filter box UI\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1067.hsg-2-7-13-02.png\" alt=\"Image of filter box UI\" \/><\/a><\/p>\n<h2>XML is a better way to filter the output<\/h2>\n<p>By using the Windows PowerShell cmdlet <strong>Get-GPOReport<\/strong> (from the GroupPolicy module from the RSAT tools), I can gain a bit of flexibility as I dive into a specific Group Policy Object. The <strong>Get-GPOReport<\/strong> cmdlet will produce two different types of reports&mdash;HTML or XML. The cmdlet also has a <strong>&ndash;path<\/strong> parameter that I use to specify the path for storing the report. Therefore, to produce a report about the BackupOnLogOff GPO that exists in my domain, I use the following syntax:<\/p>\n<p style=\"padding-left: 30px\">Get-GPOReport -Name backuponlogoff -ReportType html -Path c:\\fso\\backup.html<\/p>\n<p>I can open the produced report in Internet Explorer. The report is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1057.hsg-2-7-13-03.png\"><img decoding=\"async\" title=\"Image of report\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1057.hsg-2-7-13-03.png\" alt=\"Image of report\" \/><\/a><\/p>\n<p>Of course, generating a report to an HTML file does not help me too much&mdash;in fact, it is not much different than writing the output to the <strong>Out-GridView<\/strong> cmdlet.<\/p>\n<p>However, if I do not specify a path, the output returns to the console. Now, obviously, I do not want to write HTML to the Windows PowerShell console; in fact, I do not even want to write XML to the Windows PowerShell console, but what if I store the results in a variable and cast the variable to an XML document? Hmm &hellip; might that work?<\/p>\n<p>Well, as a matter of a fact, it does. Here is the command I use to get a GPO report in XML and store it in a variable as an XMLDocument object.<\/p>\n<p style=\"padding-left: 30px\">[xml]$xml = Get-GPOReport -Name backuponlogoff -ReportType xml<\/p>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong> &nbsp;&nbsp;Keep in mind when exploring the XML document that tab expansion works, and so there is actually very little typing required.<\/p>\n<p>The main property I like to begin with is the <strong>DocumentElement<\/strong>. From this property, I see several objects I can explore. This is shown here.<\/p>\n<p style=\"padding-left: 30px\">13:01 C:\\&gt; $xml.DocumentElement<\/p>\n<p style=\"padding-left: 30px\">xsd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : http:\/\/www.w3.org\/2001\/XMLSchema<\/p>\n<p style=\"padding-left: 30px\">xsi&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : http:\/\/www.w3.org\/2001\/XMLSchema-instance<\/p>\n<p style=\"padding-left: 30px\">xmlns&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : http:\/\/www.microsoft.com\/GroupPolicy\/Settings<\/p>\n<p style=\"padding-left: 30px\">Identifier&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Identifier<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : BackupOnLogOff<\/p>\n<p style=\"padding-left: 30px\">IncludeComments&nbsp;&nbsp;&nbsp;&nbsp; : true<\/p>\n<p style=\"padding-left: 30px\">CreatedTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2012-02-22T19:19:53<\/p>\n<p style=\"padding-left: 30px\">ModifiedTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2012-02-22T19:19:53<\/p>\n<p style=\"padding-left: 30px\">ReadTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2013-02-05T18:01:33.4004324Z<\/p>\n<p style=\"padding-left: 30px\">SecurityDescriptor&nbsp; : SecurityDescriptor<\/p>\n<p style=\"padding-left: 30px\">FilterDataAvailable : true<\/p>\n<p style=\"padding-left: 30px\">Computer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Computer<\/p>\n<p style=\"padding-left: 30px\">User&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : User<\/p>\n<p style=\"padding-left: 30px\">LinksTo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : LinksTo<\/p>\n<p>To see if the GPO is enabled on the Computer or on the User portion, I examine the enabled property from those objects, as shown here.<\/p>\n<p style=\"padding-left: 30px\">13:01 C:\\&gt; $xml.DocumentElement.Computer<\/p>\n<p style=\"padding-left: 30px\">VersionDirectory&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VersionSysvol&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enabled<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; true<\/p>\n<p>The following image shows the commands and the associated output used to obtain the XML report and to parse it.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0486.hsg-2-7-13-04.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0486.hsg-2-7-13-04.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>If I want to see the owner, I navigate through the <strong>SecurityDescriptor<\/strong> object, as shown here.<\/p>\n<p style=\"padding-left: 30px\">13:01 C:\\&gt; $xml.DocumentElement.SecurityDescriptor.Owner<\/p>\n<p style=\"padding-left: 30px\">xmlns&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-<\/p>\n<p style=\"padding-left: 30px\">http:\/\/www.microsoft.com\/&#8230; SID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">13:01 C:\\&gt; $xml.DocumentElement.SecurityDescriptor.Owner.Name<\/p>\n<p style=\"padding-left: 30px\">xmlns&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #text<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">http:\/\/www.microsoft.com\/GroupPolicy\/Types IAMMRED\\Domain Admins<\/p>\n<p>I can also easily see where the GPO links by examining the <strong>LinksTo<\/strong> object, as shown here.<\/p>\n<p style=\"padding-left: 30px\">13:02 C:\\&gt; $xml.DocumentElement.LinksTo<\/p>\n<p style=\"padding-left: 30px\">SOMName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SOMPath&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enabled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NoOverride<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">Charlotte&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iammred.net\/Charl&#8230; true&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; false<\/p>\n<p>Well, that is about it for looking at a GPO report in XML. Join me tomorrow when I will talk about more cool Group Policy stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to generate and parse a Group Policy Object report. Microsoft Scripting Guy, Ed Wilson, is here. So, I am working on my MCSE: Server Infrastructure certification and having passed the Installing and Configuring Windows Server 2012 exam (70-410), I am now studying for the [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[152,402,3,45],"class_list":["post-4202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-group-policy","tag-mcse","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to generate and parse a Group Policy Object report. Microsoft Scripting Guy, Ed Wilson, is here. So, I am working on my MCSE: Server Infrastructure certification and having passed the Installing and Configuring Windows Server 2012 exam (70-410), I am now studying for the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=4202"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4202\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=4202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}