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

9.5.2.1 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.

9.5.2.2 Using a command-line interface
> getreportsforgpo.wsf "<GPOName>" <ReportLocation> [/domain:<DomainDNSName>]
9.5.2.3 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

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.

9.5.3.1 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



Active Directory Cookbook
Active Directory Cookbook, 3rd Edition
ISBN: 0596521103
EAN: 2147483647
Year: 2006
Pages: 456

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net