Dim objRootLDAP, objContainer, objUser, objShell
Dim strUser, strName, strContainer
strUser = InputBox (" Create user","username","")
strName = InputBox ("Name Surname","Name Surname","")
'if you want usernames in lowercase
'strUser = Lcase(StrUser)
' Check username length
If Len(strUser) = 0 Then
wscript.echo "empty username ?"
wscript.quit
End If
call ADCreateUser(strUser,strName)
Function ADCreateUser(strUser,strName)
' parameters
' strName = strUser
strNewPasswd = "NA"&strUser&"99"
strContainer = "OU=YOUROU ,"
wscript.echo "username: " & strUser & " password: " & strNewPasswd
' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strContainer & objRootLDAP.Get("defaultNamingContext"))
' create user.
Set objUser = objContainer.Create("User", "cn=" & strUser)
objUser.Put "sAMAccountName", strUser
objUser.Put "displayName", strName
objUser.SetInfo
'Password set
objUser.Put "userAccountControl", 512
objUser.Put "PwdLastSet", 0
objUser.SetPassword(strNewPasswd)
objUser.SetInfo
End Function
Thursday, 18 December 2008
Create user in AD, vbscript
Create and enable user in active directory environment. Set default password, and force user to change password in first logon.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment