FindDisabledGPOs.wsf (3590B)
1 '//////////////////////////////////////////////////////////////////////////// 2 '//Copyright (c) Microsoft Corporation. All rights reserved 3 '// 4 '// Title: FindDisabledGPOs.wsf 5 '// Author: mtreit@microsoft.com 6 '// Created: 11/7/2001 7 '// 8 '// Purpose: Finds all GPOs in the domain that are disabled or partially 9 '// disabled and prints them out 10 '// options. 11 '// Revision: Ported from JScript->VBScript by dtsaltas (December 2002) 12 '// 13 '//////////////////////////////////////////////////////////////////////////// 14 15 '/////////////////////////////////////// 16 '// Initialization 17 '/////////////////////////////////////// 18 <job> 19 20 ' Include necessary libraries 21 22 <script language="JScript" src="Lib_CommonGPMCFunctions.js"/> 23 <script language="VBScript"> 24 25 ' Create global objects for use by the rest of the script 26 Dim GPM : Set GPM = CreateObject("GPMgmt.GPM") 27 Dim Constants : Set Constants = GPM.GetConstants() 28 29 '/////////////////////////////////////// 30 '// Main script 31 '/////////////////////////////////////// 32 33 ' Handle command line arguments 34 Dim ArgumentList : Set ArgumentList = ProcessCommandLineArguments() 35 Dim szDomainName : szDomainName = ArgumentList.Item("Domain") 36 37 ' Initialize the Domain object 38 Dim GPMDomain : Set GPMDomain = GPM.GetDomain(szDomainName, "", Constants.UseAnyDC) 39 40 ' Get all GPOs in the domain 41 Dim GPMSearchCriteria 42 Set GPMSearchCriteria = GPM.CreateSearchCriteria() 43 Dim GPOList 44 Set GPOList = GPMDomain.SearchGPOs(GPMSearchCriteria) 45 46 47 ' Print out the GPOs that are totally disabled 48 WScript.Echo vbCrLf & "== GPOs that are completely disabled ==" 49 50 For Each objGPO in GPOList 51 If objGPO.IsUserEnabled = False AND objGPO.IsComputerEnabled = False Then 52 WScript.Echo objGPO.ID & " - " & objGPO.DisplayName 53 End If 54 Next 55 56 57 ' Print out the GPOs where the computer side is disabled 58 WScript.Echo vbCrLf & "== GPOs with the computer settings disabled ==" 59 60 For Each objGPO in GPOList 61 If objGPO.IsUserEnabled = True AND objGPO.IsComputerEnabled = False Then 62 WScript.Echo objGPO.ID & " - " & objGPO.DisplayName 63 End If 64 Next 65 66 ' Print out the GPOs where the user side is disabled 67 WScript.Echo vbCrLf & "== GPOs with the user settings disabled ==" 68 69 For Each objGPO in GPOList 70 If objGPO.IsUserEnabled = False AND objGPO.IsComputerEnabled = True Then 71 WScript.Echo objGPO.ID & " - " & objGPO.DisplayName 72 End If 73 Next 74 75 '/////////////////////////////////////// 76 '// Function Definitions 77 '/////////////////////////////////////// 78 79 ' Returns a dictionary object 80 ' containing the named arguments and values that were passed in 81 Function ProcessCommandLineArguments() 82 83 Dim strDomainName : strDomainName = "" 84 85 ' Check if this is cscript. If not, print an error and bail out 86 87 If UCase(Right(WScript.FullName,11)) = "WSCRIPT.EXE" Then 88 WScript.Echo "You must use cscript.exe to execute this script." 89 WScript.Quit(-1) 90 End If 91 92 Dim Result : Set Result = CreateObject("Scripting.Dictionary") 93 94 95 If WScript.Arguments.Named.Exists("Domain") Then 96 97 strDomainName = WScript.Arguments.Named("Domain") 98 End If 99 100 101 ' Get the current domain if none was specified 102 If strDomainName = "" Then 103 104 strDomainName = GetDNSDomainForCurrentUser() 105 End If 106 107 Result.Add "Domain", strDomainName 108 109 Set ProcessCommandLineArguments = Result 110 111 End Function 112 113 </script> 114 115 <!-- Usage and command line argument information --> 116 <runtime> 117 118 <description> 119 Searches for all disabled GPOs in a given domain. 120 </description> 121 122 <named name="Domain" helpstring="DNS name of domain" type="string" required="false" /> 123 124 <example> 125 Example: FindDisabledGPOs.wsf /domain:Test.MyDomain.com 126 </example> 127 128 </runtime> 129 130 </job>