WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE COM ADO CDO ADSI LDAP
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Setting Group Policy Objects


Scripting the addition of Group Policy links Administrators may need a way of automating the modification of the Group Policy objects (GPOs) that apply to a given site, domain, or organizational unit. This article contains a sample script that, when run on a computer that is a member of a domain, displays the list of available GPOs and allows the user to manually add a GPO link. You should consider the sample script in this article only a guide as to what can be accomplished. You should modify it to meet your specific needs.

Portions of this script rely on IADsTools, a Component Object Model (COM) object that can be used for many functions, including the one described in this article to enumerate GPOs. IADsTools is included with the Windows 2000 Support tools, which are located in the Support\Tools folder on the Microsoft Windows 2000 Professional or Server CD-ROMs. Detailed information about the function parameters for IADsTools is located in the Windows 2000 Support Tools documentation.

http://support.microsoft.com/?kbid=248392

Here is the UNDEBUGGED translation:

;GPOLLINK.WBT
;Purpose:  adds a Group Policy link to an existing Site, Domain, or OU

;NOTE:  if you modify this script and pass variables to the IADSTOOLS functions, these variables
;must be typed when you pass them in.  Please see "Programs -> Windows 2000 Support Tools -> Tools Help"
;for more information

;the IADSTOOLS com object that ships with the Support Tools has many
;functions that make it easier to retrieve data stored in the DS

;instance the object
DLL = ObjectCreate("iadstools.dcfunctions")

;bind to the Site, Domain, or OU (SDOU) that you want to manage the links on
;specify the PDC name when doing this
SDOU = ObjectGet("LDAP://ServerName/dc=MyDomain,dc=com")

;call the IADSTOOLS function to enumerate the Group Policy Objects (GPOs)
Result = DLL.GetGPOs("MyDomain.com","ServerName")

;if a positive number of GPOs is returned, then list them
If result > 0 Then
   ;we found gpos in the list
   For i = 1 To result
      ;print them out to the display
      Message("GPO name & ID", StrCat( DLL.gponame(i), @LF, dll.gpoguid(i)))
   Next
Else
   ;we didn;t find any - none to display
   Message("Notice", "No GPOs were found.")
EndIf

;again, if a positive number of GPOs is returned, than we can
;offer the user the option of linking a GPO to the selected SDOU
currentGPLIST = ""
If Result > 0
   ;display the SDOU we will be modifying just in case it is incorrect before they
   ;make any modification
   Message( "The SDOU you will be modifying is:", SDOU.adspath )
   ;ask the user for the textual name of the existing GPO to add
   askGUID = AskLine("GPO Info", "Enter the name of the GPO to add (case is not important):", "")

   ;if they hit cancel or entered nothing, exit
   If askGUID = ""
      Message("GPO Info", "You must specify the name of the GPO")
   Else
      ;cycle through the GPOs we got back from IADSTOOLS and find the GPO the user
      ;entered
      For i=1 To result
         ;we drop both items being compared to lower case to rule out case
         If StrLower(DLL.gponame(i)) == StrLower(askGUID)
            ;we found a match.  Determine the links that already exist, if any
            currentGPLIST = SDOU.get("gpLink")

            ;construct a new link to add to the existing links
            currentGPLIST = StrCat( currentGPLIST , "[LDAP://CN=" , DLL.gpoguid(i) , ",CN=Policies,CN=System," , DLL.getdefaultnamingcontext("ServerName") , ";0]")

            ;write the new list back to the gpLink attribute on the SDOU
            SDOU.put("gpLink",currentGPLIST)

            ;commit the change
            SDOU.SetInfo()

            ;tell the user we completed successfully
            Message("GPO Info", StrCat( "Successfully added a link to this SDOU for the GPO (" , DLL.gponame(i) , ")" ))

            ;only process the first one we come to that has the correct name
            Exit
         EndIf
      Next
   EndIf
EndIf

Article ID:   W17099
File Created: 2009:11:03:09:40:10
Last Updated: 2009:11:03:09:40:10