Viewing the Settings of a GPO






Viewing the Settings of a GPO

Problem

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

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.
	' ------ SCRIPT CONFIGURATION ------
	strGPO        = "<GPOName>"         ' e.g. Sales GPO
	strDomain     = "<DomainDNSName>"   ' e.g. rallencorp.com
	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."
	   WScript.Quit
	elseif objGPOList.Count > 1 then
	   WScript.Echo "Found more than one matching GPO. Count: " & _
	                 objGPOList.Count
	   WScript.Echo "Exiting."
	   WScript.Quit
	else
	   WScript.Echo "Found GPO: " & objGPOList.Item(1).DisplayName
	end if

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

	' 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
	   next
	   WScript.Echo vbCrLf
	end if '
	Display the result
	if Err.Number <> 0 then
	   WScript.Echo "Error generating report."
	   WScript.Echo "Error: " & Err.Description
	else
	   WScript.Echo "Reported saved to " & strReportFile
	end if

Discussion

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

Using VBScript

Use a GPMSearchCriteria object to find the GPO that is equal to the display name of the GPO specified in the configuration section. Use an if else conditional statement to ensure that only one GPO is returned. If zero or more than one are returned, abort the script. If only one is returned, you can use 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.

See Also

MSDN: GPMGPO.GenerateReportToFile



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows