尝试将用户添加到Active Directory时出错

时间:2012-12-28 19:12:02

标签: vbscript active-directory

我现在不知所措;我已经尝试过几种不同的方法,但不断收到There is no such object on the server at character 20,2的错误。

这一行是

Set objOU = GetObject("LDAP://ou=users,dc=asp,dc=rippe,dc=com")

我在用户旁边将OU更改为CN时收到了其他错误。

期望的最终结果是从HTML表单中获取所有变量,然后脚本将运行以在我们的域上创建新用户。

我还没有将用户添加到群组中,因为我无法通过这个障碍。

Dim strID,StrFName,strLName,strFirm,strPwd,strServer,strLMS,strSql,strLMSV

strID = zademo
strFName = Demo
strLName = Tester
strFirm = Demo
strPwd = za1234
strServer = rkasp01
strLMS = y
strSql = y
strLMSV = y
strDisplay = strLName & ", " & strFName


'Create Citrix User Account

If strSql = y OR strLMSV = y Then

    Set objOU = GetObject("LDAP://ou=Users,dc=asp,dc=rippe,dc=com")

    Set objUser = objOU.Create("User", "cn=" & strDisplay)
    objUser.Put "sAMAccountName", strID
    objUser.Put "Description", strFirm

    objUser.Put "givenName", strFName
    objUser.Put "sn", strLName
    objUser.Put "displayName", strDisplay
    objUser.Put "homedirectory", "\\rkpdc\" & strFirm & "\" & strID
    objUser.Put "scriptpath", strFirm & ".bat"
    objUser.SetInfo

End If

objUser.SetPassword strPwd
objUser.Put "PasswordExpired", CLng(1)
objUser.AccountDisabled = FALSE
objUser.SetInfo

3 个答案:

答案 0 :(得分:1)

  

设置objOU = GetObject(“LDAP:// ou = Users,dc = asp,dc = rippe,dc = com”)

通常“用户”是容器,而不是OU。

尝试:

  

设置objOU = GetObject(“LDAP:// CN = Users,dc = asp,dc = rippe,dc = com”)

答案 1 :(得分:0)

您是否尝试过将example.com替换为实际域名。

GetObject("LDAP://example.com/OU=Users,DC=asp,DC=rippe,DC=com")

答案 2 :(得分:0)

Option Explicit
Dim strUserName
Dim objRootLDAP
Dim objContainer
Dim objNewUser
strUserName = "MorganTestUser"

Set objRootLDAP = GetObject("LDAP://rootDSE")

' You can give your own OU like LDAP://OU=TestOU instead of LDAP://CN=Users
Set objContainer = GetObject("LDAP://CN=Users," & _
objRootLDAP.Get("defaultNamingContext")) 

Set objNewUser = objContainer.Create("User", "cn=" & strUserName)
objNewUser.Put "sAMAccountName", strUserName
objNewUser.Put "givenName", "Morgan"
objNewUser.Put "sn", "TestUser"
objNewUser.Put "displayName", "Morgan TestUser"
objNewUser.Put "Description", "AD User created by VB Script"
objNewUser.SetInfo

objNewUser.SetPassword "MyPassword123"
objNewUser.Put "PasswordExpired", CLng(1)
objNewUser.AccountDisabled = FALSE

MsgBox ("New Active Directory User created successfully by using VB Script...")

WScript.Quit