Written
July 20, 2010
Hi, I've tried using this script to apply a policy to a new OU and I get the following error:
apply gpo.wsf(25, 9) Windows Script Host: Invalid entity reference
I've changed the references in the script to match our AD set up. The OU path is correct as I used another script to create it. Here's the full script:
On Error Resume Next
Set objContainer = GetObject _
("LDAP://ou=Desktops,ou=Team 15,ou=Science,ou=2010 reorganisation,dc=internal,dc=sanger,dc=ac,dc=uk")
strExistingGPLink = objContainer.Get("gPLink")
strGPODisplayName = "2010 generic desktop"
strGPOLinkOptions = 2
strNewGPLink = "[" & GetGPOADsPath & ";" & strGPOLinkOptions & "]"
objContainer.Put "gPLink", strExistingGPLink & strNewGPLink
objContainer.Put "gPOptions", "0"
objContainer.SetInfo
Function GetGPOADsPath
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://cn=Policies,cn=System,dc=internal,dc=sanger,dc=ac,dc=uk>;;" & _
"distinguishedName,displayName;onelevel"
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
If objRecordSet.Fields("displayName") = strGPODisplayName Then
GetGPOADsPath = "LDAP://" & objRecordSet.Fields("distinguishedName")
objConnection.Close
Exit Function
End If
objRecordSet.MoveNext
Loop
objConnection.Close
End Function