Hey all, I have a script at work here that is basically a modified version of another script that connects to a group of domains, does a query for admin groups, checks memberships of those groups, etc. Sample code for the piece that I'm having problems with is below:
The problem that I'm having is that at some point arrDomains will probably be fed from a text for or something similar, so I cannot hard-code values for objAdRootDSE. I have to be able to parse the array elements, construct the LDAP:// connection strings manually, then connect to the domains. I've traced the problem to this line:
varConfigNC does not get assigned to anything, so my WQL statement is missing an element. It comes out looking like this:
I've had these problems with other scripts where I couldn't dynamically create the connections, and I always had to put in some statements where a user could make a choice that would then set objAdRootDSE manually to the correct value. But that won't work in this case because the list of domains could change regularly.
I have tried using:
both with and without the quotes, but I'm not sure how else to do it. Any suggestions?
Code:
arrDomains = Array("domain1.local", "domain2.local", "domain3.local",
"child1.domain1.local", "child2.domain2.local", "child3.domain3.local")
For i = 0 to UBound(arrDomains)
'Unless you want to change the domain to check or the format of the
emailed info, nothing below really needs to be modified.
On Error Resume Next
numPersonCount = 0
arrDNames = Split(arrDomains(i), ".")
strDSE = "LDAP://"
For x = 0 to UBound(arrDNames)
If x = UBound(arrDNames) Then
strDSE = strDSE & "DC=" & arrDNames(x)
Else
strDSE = strDSE & "DC=" & arrDNames(x) & ","
End If
Next
Wscript.Echo strDSE
Set objAdRootDSE = GetObject("strDSE")
Set objRS = CreateObject("adodb.recordset")
varConfigNC = objAdRootDSE.Get("DefaultNamingContext")
Wscript.Echo "varConfigNC = " & varConfigNC
strConnstring = "Provider=ADsDSOObject"
'strWQL = "SELECT ADsPath FROM 'LDAP://" & varConfigNC & "' WHERE
modifyTimeStamp > '" & strTimeInUTC & "' and (objectCategory = 'Group') and
(name = 'Domain Admins' or name = 'Administrators' or name = 'Enterprise Admins' or name = 'Schema Admins')"
strWQL = "SELECT ADsPath FROM '"& varConfigNC & "' WHERE
(objectCategory = 'Group') and (name = 'Domain Admins' or name =
'Administrators' or name = 'Enterprise Admins' or name = 'Schema Admins')"
Wscript.Echo strWQL
objRS.Open strWQL, strConnstring
Wscript.Echo "Connection Made"
Do until objRS.eof
The problem that I'm having is that at some point arrDomains will probably be fed from a text for or something similar, so I cannot hard-code values for objAdRootDSE. I have to be able to parse the array elements, construct the LDAP:// connection strings manually, then connect to the domains. I've traced the problem to this line:
Code:
varConfigNC = objAdRootDSE.Get("DefaultNamingContext")
varConfigNC does not get assigned to anything, so my WQL statement is missing an element. It comes out looking like this:
Code:
SELECT ADsPath FROM ' WHERE (objectCategory = 'Group') and (name =
'Domain Admins' or name = 'Administrators' or name = 'Enterprise Admins' or
name = 'Schema Admins')
I've had these problems with other scripts where I couldn't dynamically create the connections, and I always had to put in some statements where a user could make a choice that would then set objAdRootDSE manually to the correct value. But that won't work in this case because the list of domains could change regularly.
I have tried using:
Code:
Set objAdRootDSE = GetObject("strDSE")
both with and without the quotes, but I'm not sure how else to do it. Any suggestions?