Recipe 9.5 Viewing the Settings of a GPO

9.5.1 Problem

You want to view the settings that have been defined on a GPO.

9.5.2 Solution Using a graphical user interface
  1. Open the GPMC snap-in.

  2. In the left pane, expand the Forest container, expand the Domains container, browse to the domain of the target GPO, and expand the Group Policy Objects container.

  3. Click on the target GPO.

  4. In the right pane, click on the Settings tab.

  5. Click the Show All link to display all configured settings. Using a command-line interface
> getreportsforgpo.wsf "<GPOName>" <ReportLocation> [/domain:<DomainDNSName>] Using VBScript
' This code generates a HTML report of all the properties 
' and settings for a GPO. 
strGPO        = "<GPOName>"         ' e.g. Sales GPO
strDomain     = "<DomainDNSName>"   ' e.g.
strReportFile = "<FileNameAndPath>" ' e.g. c:\gpo_report.html
' ------ END CONFIGURATION ---------

set objGPM = CreateObject("GPMgmt.GPM")
set objGPMConstants = objGPM.GetConstants( )
' Initialize the Domain object
set objGPMDomain = objGPM.GetDomain(strDomain, "", objGPMConstants.UseAnyDC)

set objGPMSearchCriteria = objGPM.CreateSearchCriteria
objGPMSearchCriteria.Add objGPMConstants.SearchPropertyGPODisplayName, _
                         objGPMConstants.SearchOpEquals, cstr(strGPO)
set objGPOList = objGPMDomain.SearchGPOs(objGPMSearchCriteria)

if objGPOList.Count = 0 then
   WScript.Echo "Did not find GPO: " & strGPO
   WScript.Echo "Exiting."
elseif objGPOList.Count > 1 then
   WScript.Echo "Found more than one matching GPO. Count: " & _
   WScript.Echo "Exiting."
   WScript.Echo "Found GPO: " & objGPOList.Item(1).DisplayName
end if

set objGPMResult = objGPOList.Item(1).GenerateReportToFile( _
                          objGPMConstants.ReportHTML, _

' This will throw an exception if there were any errors
' during the actual operation.
on error resume next
objGPMResult.OverallStatus( )

if objGPMResult.Status.Count > 0 then
   WScript.Echo "Status message(s): " & objGPMResult.Status.Count
   for i = 1 to objGPMResult.Status.Count
      WScript.Echo objGPMResult.Status.Item(i).Message
   WScript.Echo vbCrLf
end if

' Display the result
if Err.Number <> 0 then
   WScript.Echo "Error generating report."
   WScript.Echo "Error: " & Err.Description
   WScript.Echo "Reported saved to " & strReportFile
end if

9.5.3 Discussion

The GPMC can generate an XML or HTML report that contains all of the settings in a GPO. See Recipe 9.6 for more on how to modify GPO settings. Using VBScript

I use a GPMSearchCriteria object to find the GPO that is equal to the display name of the GPO specified in the configuration section. I use an if elseif else conditional statement to ensure that only one GPO is returned. If zero or more than one are returned, I abort the script. If only one is returned, I used the GPMGPO.GenerateReportToFile method to generate a report of all the settings in the GPO. The first parameter for GenerateReportToFile is a constant that determines the type of report to generate (i.e., HTML or XML). The second parameter is the path of the file to store the report.

9.5.4 See Also

MSDN: GPMGPO.GenerateReportToFile

    Chapter 3. Domain Controllers, Global Catalogs, and FSMOs
    Chapter 6. Users
    Appendix A. Tool List