I'm trying to create users and then add the users to a group. It's working greate if i leave the add to group part out.
There is something wrong with the loop in the bottom. On the line from 116 to 119 it defines the group and the path to the group. The first user is ok then it loops and dubble adds the group and path again.
I try to explain it a litle bit more...
The msgBox on line 119 tells me that the group cn=mygroup,ou=mygroupofusers,ou=user,ou=company,dc=mydom,dc=com is going to get users in it. Greate exactly what i want! Then the script loops and comes to the msgBox again and tells me that the path is now cn=mygroup,ou=mygroupofusers,ou=user,ou=company,dc=mydom,dc=com,cn=mygroup,ou=mygroupofusers,ou=user,ou=company,dc=mydom,dc=com and that isnt right and i get an error telling med that the objekt couldent be found.. Is there a flush line i can add to the script for strGroupName or something else maybe..
PS as u can se i have tried to use replace but i only get another error so i have commented it out
There is something wrong with the loop in the bottom. On the line from 116 to 119 it defines the group and the path to the group. The first user is ok then it loops and dubble adds the group and path again.
I try to explain it a litle bit more...
The msgBox on line 119 tells me that the group cn=mygroup,ou=mygroupofusers,ou=user,ou=company,dc=mydom,dc=com is going to get users in it. Greate exactly what i want! Then the script loops and comes to the msgBox again and tells me that the path is now cn=mygroup,ou=mygroupofusers,ou=user,ou=company,dc=mydom,dc=com,cn=mygroup,ou=mygroupofusers,ou=user,ou=company,dc=mydom,dc=com and that isnt right and i get an error telling med that the objekt couldent be found.. Is there a flush line i can add to the script for strGroupName or something else maybe..
PS as u can se i have tried to use replace but i only get another error so i have commented it out
Code:
OPTION EXPLICIT
DIM objConn '
DIM objParent '
DIM objOu '
DIM objGroup '
DIM objGroupName '
DIM objUser '
DIM rsAnvandare '
DIM strDbPath '
DIM strParent '
DIM strPwd '
DIM strGroupName '
DIM strGroupNetBiosName '
DIM intGroupType '
DIM strOu '
DIM strCN '
DIM strSAMName '
DIM strSAMEnd '
DIM strUPN '
DIM strPassword '
DIM intRaknare '
DIM strUserName '
DIM objGroupMember '
strDbPath = "D:\SHARE\dbAdmin.mdb"
intGroupType = &H80000002 'Global Security
intTest = 0
SET objConn=CreateObject("ADODB.Connection")
objConn.Provider="Microsoft.Jet.OLEDB.4.0"
objConn.Open strDbPath
SET rsTest1 = objConn.Execute("SELECT * FROM tblTest1;")
strGroupName = "cn="&rsTest1("strTest2")
strGroupNetBiosName = rsTest1("strTest2")
strOu = "ou="&rsTest1("strTest2")
strParent = "company"
IF strParent = "company" THEN
strPwd = inputbox("password for domain: ?","Account create password","***")
END IF
IF NOT strPwd = "" THEN
IF strParent = "company" THEN
strParent = "ou=user,ou=company,dc=mydom,dc=com"
END IF
SET objParent = GetObject ("LDAP://" & strParent)
SET objTest3 = objParent.Create("organizationalUnit", strTest3)
objTest3.SetInfo
SET objTest3 = NOTHING
SET objParent = NOTHING
SET objParent = GetObject ("LDAP://" & strOu&", "& strParent)
SET objGroup = objParent.Create("group", strGroupName)
objGroup.Put "sAMAccountName", strGroupNetBiosName
objGroup.Put "groupType", intGroupType
objGroup.SetInfo
SET objGroup = NOTHING
SET objParent = NOTHING
' Beginning of LOOP
DO UNTIL rsTest1.EOF
strCN = "cn="&rsTest1("strForNamn")&" "&rsTest1("strEfterNamn")
strSAMName = rsTest1("strTest2")&rsTest1("strTest1Namn")
strUPN = strSAMName&"@lbs.se"
strPassword = rsTest1("strDomainPwd")
SET objParent = GetObject ("LDAP://" & strTest3&", "& strParent)
SET objUser = objParent.Create("user", strCN)
objUser.Put "sAMAccountName", strSAMName
objUser.Put "userPrincipalName", strUPN
objUser.SetInfo
objUser.GetInfo
objUser.Put "displayName", rsTest3("strForNamn") &" "&rsTest1("strEfterNamn")
objUser.Put "description", rsTest1("strTest2") &" elev"
objUser.SetPassWord strPassword
objUser.AccountDisabled = FALSE
objUser.SetInfo
SET objParent = NOTHING
' The next line gets the path to the group and isnt flushed in the next loop
' So something is wrong here...
strGroupName = strGroupname &","& strTest3 &","& strParent
' strGroupName = Replace(strGroupname) ' ","& strTest3 &","& strParent)
strUserName = strCN &","& strParent
msgBox strGroupName
SET objGroupMember = GetObject ("LDAP://" & strGroupName)
objGroupMember.Add(objUser.ADsPath)
objGroupMember.SetInfo
SET objGroupMember = NOTHING
SET objUser = NOTHING
intTest4 = intTest4 + 1
rsTest1.MoveNext
LOOP
MsgBox "SCRIPT DONE "&intTest4&" here here ",0,"create account done"
ELSE
MsgBox "No password. Script avslutat",0,"create account done"
END IF
SET objConn = NOTHING