Thanks for all the info. In the end I got the following script working
which reads in names from a list of names in a text file. Its dog slow
though, but still quicker than creating them myself.

' ------ SCRIPT CONFIGURATION ------
'intNumUsers = 1000         ' Number of users to create
strParentDN = "ou=sales,dc=ollymarshall,dc=com" ' e.g.
ou=Users,dc=ollymarshall,dc=com
' ------ END CONFIGURATION ---------

' Taken from ADS_USER_FLAG_ENUM
Const ADS_UF_NORMAL_ACCOUNT = 512
CONST ForReading = 1

set objParent = GetObject("LDAP://"; & strParentDN)
Set fso = CreateObject("Scripting.FileSystemObject")

inputFile = "names.txt"
set f = fso.OpenTextFile(inputFile, ForReading, True)



Do While f.AtEndOfLine <> True
   strInputUserName = trim(f.ReadLine)  
   strUser = strInputUserName
   Set objUser = objParent.Create("User", "cn=" & strUser)
   objUser.Put "sAMAccountName", strUser

' CORRECTION: If you don't set userAccountControl, then by default
'             the value of 514 (normal account + disabled) will be set
for it.
'             In this instance by setting it to 512, the account will
not
'             be disabled, and if you have password complexity enabled
in
'             your forest, the script will fail because a password was
not
'             set prior to the account being enabled.  The solution is
to 
'             not set userAccountControl here.
'   objUser.Put "userAccountControl", ADS_UF_NORMAL_ACCOUNT

   objUser.SetInfo
   objUser.SetPassword "xxxxxxxxxxxxx"
   objUser.AccountDisabled=FALSE
   objUser.SetInfo
   wscript.echo "Created " & strUser

loop

WScript.Echo ""
WScript.Echo "Created " & intNumUsers & " users"
List info   : http://www.activedir.org/mail_list.htm
List FAQ    : http://www.activedir.org/list_faq.htm
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/

Reply via email to