I am starting a new thread as the old one is kinda long.
Here is my script, i am trying to add a user to the domain admins group in ADS. it doesn't work. Any help would be much appreciated.
On Error Resume Next
Dim conADS, rstADS, cmdADS, strADS, strDefaultDomainNC
Dim strCN, strGivenN, strLastN, strFullN, strDesc, strLocation, strEmail, strMsg
Dim strAdmin, strDomAdmin
Dim sErrDesc, sErrNumb, errDict, strErrMsg, strErrYes
Dim sUser, userDict, stUser
'Get Default namaing context from ads server
strDefaultDomainNC = GetObject("LDAP://RootDSE").Get("DefaultNamingContext")
Set conADS = CreateObject("ADODB.Connection")
conADS.Provider = "ADsDSOObject"
conADS.Open "Active Directory Provider"
Set cmdAds = CreateObject("ADODB.Command")
Set cmdADS.ActiveConnection = conADS
strADS = "SELECT samAccountName, givenName, sn, adsPath" & _
" FROM 'LDAP://" & strDefaultDomainNC & "'WHERE objectClass= 'user'"
strDomAdmin = "Domain Admins"
cmdADS.CommandText = strADS
'Open connection to ADS Server
Set rstADS = cmdADS.Execute
'Cycle through all users in ADS
Do While Not rstADS.EOF
Set objUser = GetObject(rstADS.Fields("ADsPath").Value)
strCN = objUser.samAccountNAme
strGivenN = objUser.givenName
strLastN = objUser.sn
strFullN = objUser.fullname
'check to see if account is really a user
'If len(strLastN) > 0 Then
If strCN = "testthis" then
set objGroup = GetObject("LDAP://" & strDomAdmin)
' Wscript.Echo objGroup
' Wscript.Echo objUser
objGroup.Add(objUser.ADsPath)
' objGroup.Add("LDAP://cn=" & strCN & ",cn=users,dc=domain,dc=net") DOES NOT WORK
Wscript.Echo "Done"
End If
rstADS.MoveNext
Loop
Here is my script, i am trying to add a user to the domain admins group in ADS. it doesn't work. Any help would be much appreciated.
On Error Resume Next
Dim conADS, rstADS, cmdADS, strADS, strDefaultDomainNC
Dim strCN, strGivenN, strLastN, strFullN, strDesc, strLocation, strEmail, strMsg
Dim strAdmin, strDomAdmin
Dim sErrDesc, sErrNumb, errDict, strErrMsg, strErrYes
Dim sUser, userDict, stUser
'Get Default namaing context from ads server
strDefaultDomainNC = GetObject("LDAP://RootDSE").Get("DefaultNamingContext")
Set conADS = CreateObject("ADODB.Connection")
conADS.Provider = "ADsDSOObject"
conADS.Open "Active Directory Provider"
Set cmdAds = CreateObject("ADODB.Command")
Set cmdADS.ActiveConnection = conADS
strADS = "SELECT samAccountName, givenName, sn, adsPath" & _
" FROM 'LDAP://" & strDefaultDomainNC & "'WHERE objectClass= 'user'"
strDomAdmin = "Domain Admins"
cmdADS.CommandText = strADS
'Open connection to ADS Server
Set rstADS = cmdADS.Execute
'Cycle through all users in ADS
Do While Not rstADS.EOF
Set objUser = GetObject(rstADS.Fields("ADsPath").Value)
strCN = objUser.samAccountNAme
strGivenN = objUser.givenName
strLastN = objUser.sn
strFullN = objUser.fullname
'check to see if account is really a user
'If len(strLastN) > 0 Then
If strCN = "testthis" then
set objGroup = GetObject("LDAP://" & strDomAdmin)
' Wscript.Echo objGroup
' Wscript.Echo objUser
objGroup.Add(objUser.ADsPath)
' objGroup.Add("LDAP://cn=" & strCN & ",cn=users,dc=domain,dc=net") DOES NOT WORK
Wscript.Echo "Done"
End If
rstADS.MoveNext
Loop