Assigns the Group Policy link Sales Policy to the Sales OU in Active Directory.
On Error Resume NextSet objContainer = GetObject _("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")strExistingGPLink = objContainer.Get("gPLink")strGPODisplayName = "Sales Policy"strGPOLinkOptions = 2strNewGPLink = "[" & GetGPOADsPath & ";" & strGPOLinkOptions & "]"objContainer.Put "gPLink", strExistingGPLink & strNewGPLinkobjContainer.Put "gPOptions", "0"objContainer.SetInfoFunction GetGPOADsPathSet objConnection = CreateObject("ADODB.Connection")objConnection.Open "Provider=ADsDSOObject;"Set objCommand = CreateObject("ADODB.Command")objCommand.ActiveConnection = objConnectionobjCommand.CommandText = _"<LDAP://cn=Policies,cn=System,dc=NA,dc=fabrikam,dc=com>;;" & _"distinguishedName,displayName;onelevel"Set objRecordSet = objCommand.ExecuteWhile Not objRecordSet.EOFIf objRecordSet.Fields("displayName") = strGPODisplayName ThenGetGPOADsPath = "LDAP://" & objRecordSet.Fields("distinguishedName")objConnection.CloseExit FunctionEnd IfobjRecordSet.MoveNextWendobjConnection.CloseEnd Function
This is a VB Script, this can be used by saving the file in .vbs file