Create local Windows accounts using a script

If you are faced with the boring task of creating say a large amount of users on Windows 2003 server then use the following script, it works with a text file.

  1. Create a list of users in a file called users.txt (put each user on a separate line)
  2. Copy the script below into another file called Create_users.vbs

‘———-
strComputer = “.”

‘local computer

set objArgs = wscript.arguments

if objArgs.count <> 1 then
wscript.echo “Usage: ” & wscript.scriptFullName & ” <text_file_containing_user_names>”
wscript.quit
end if
strServerListFile=objArgs(0)
set fs = CreateObject(“Scripting.FileSystemObject”)
if NOT fs.fileExists(strServerListFile) then
wscript.echo “Text file containing User list not found.”
wscript.quit
end if
set fl = fs.openTextFile(strServerListFile)
while not fl.atEndOfStream
strUser=fl.readLine
wscript.echo strUser

‘strUser contain the name of user read from text file.
‘Create user account and assign values for different properties here
‘——————————————————————————-
Set colAccounts = GetObject(“WinNT://” & strComputer & “”)
Set objUser = colAccounts.Create(“user”,strUser)
objUser.SetPassword “09iu%4et”
objUser.SetInfo ‘needed to save property values for user.
‘Add other user properties here:
‘——————————————————————————-
‘End creating user account
wend
fl.close

  1. Save both files to the same directory e.g. c:temp
  2. In a command prompt enter the directory c:temp and type Create_users.vbs users.txt
  3. You should get a window showing the news have been added, now goto Start, run compmgmt.msc and see if the new users have been created.NB. Please note that all the accounts will have the default password of 09iu%4et unless you change it near the bottom of the script.

Leave a Comment

Your email address will not be published.

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: