' This code copies the attributes in the Attrs array from an
' existing object to a new one.
' ------ SCRIPT CONFIGURATION ------
arrAttrs = Array("department","co","title","l", "c", "st")
strParentDN = "<ParentContainer>" ' e.g. cn=Users,dc=rallencorp,dc=com
strTemplateUser = "<TemplateUserName>" ' e.g. template-user-sales
strNewUser = "<NewUserName>" ' e.g. jdoe
strPassword = "<Password>"
' ------ END CONFIGURATION ---------
Const ADS_UF_NORMAL_ACCOUNT = 512 ' from ADS_USER_FLAG_ENUM
Set objTemplate = GetObject("LDAP://cn=" & strTemplateUser & _
"," & strParentDN)
Set objParent = GetObject("LDAP://" & strParentDN)
Set objUser = objParent.Create("user", "cn=" & strNewUser)
objUser.Put "sAMAccountName", strNewUser
for each strAttr in arrAttrs
objUser.Put strAttr, objTemplate.Get(strAttr)
next
objUser.SetInfo
objUser.SetPassword(strPassword)
objUser.SetInfo
objUser.Put "userAccountControl", ADS_UF_NORMAL_ACCOUNT
objUser.AccountDisabled = FALSE
objUser.SetInfo
WScript.Echo "Successfully created user"