Hi all,
I am trying to use Excel to create new users in Active directory (LDAP), but when I run the macro, I get the error saying:
"Runtime Error '70' : Permission Denied." I might have either missed something in the connection, or I might have placed the user credentials at wrong places. I am placing the code here. Please help me.
Code::
Sub Createusers()
Dim Row As Integer
Dim oUser As IADsUser
Set rootDSE = GetObject("LDAP://server:portnumber/rootDSE dn")
Set oOU = GetObject("LDAP://server:portnumber/user OU")
Row = 2
Do Until Cells(Row, 1) = Empty
givenName = Trim(Cells(Row, 4).Value)
sn = Trim(Cells(Row, 5).Value)
cn = givenName & " " & sn
uid = Cells(Row, 6).Value
mail = Cells(Row, 7).Value
userpassword = Cells(Row, 8).Value
groups = Cells(Row, 9).Value
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Properties("User ID") = "username"
conn.Properties("Password") = "password"
conn.Properties("Encrypt Password") = False
conn.Open "ADs Provider", "username", "password"
ldapStr = "<"LDAP://server:portnumber/rootDSE dn">;(&(objectCategory=user));adspath;subtree"
Set rs = conn.Execute(ldapStr)
While rs.RecordCount > 0
ldapStr = "<"LDAP://server:portnumber/rootDSE dn">;(&(objectCategory=user));adspath;subtree"
Set rs = conn.Execute(ldapStr)
Wend
' Update User Record
Set oUser = oOU.Create("user", "uid=" & uid)
oUser.Put "cn", cn
oUser.Put "givenName", givenName
oUser.Put "sn", sn
oUser.Put "uid", uid
oUser.Put "userpassword", userpassword
StrobjGroup1 = ""LDAP://server:portnumber/CN=" & groups & "groups OU"
Set objGroup1 = GetObject(StrobjGroup1)
objGroup1.Add (oUser.ADsPath)
Set oUser = Nothing
Row = Row + 1
Loop
conn.Close
End Sub
Thanks in advance.
Bookmarks