Help - Search - Members - Calendar
Full Version: Create Accounts from Command Line
Neowin Forums > Windows Support > Windows NT4/2000/2003/2008 Server
Sleeper
Im wanting to create a batch file that will create local user accounts for all our Systems Admin team on a server. I know that I can use "net user" but this does not let you specify that you want the user to change the password at next logon.

I've getting a hold of addusers.exe but this does not seem to be compatibale with Windows Server 2003.

Has anyone got any other ideas?

Regards.
Joel
PwdLastSet.vbs
CODE
' PwdLastSet.vbs
' VBScript to FORCE a user's password change
' Author Ulrich P amended by Guy Thomas
' Version 2.0 - October 17th 2004
' --------------------------------------------------------------'
Option Explicit
Dim objOU, objUser, objRootDSE
Dim strContainer, strLastUser, strDNSDomain, strPassword
Dim intCounter, intAccValue, intPwdValue

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
intAccValue = 544
intPwdValue = 0

' -------------------------------------------------------------'
' Important change OU= to reflect your domain
' -------------------------------------------------------------'

strContainer = "OU=Accounts, "
strPassword = "P@ssw0rd"

' -------------------------------------------------------------'
' Makes the user change P@ssw0rd at first logon
' -------------------------------------------------------------'

strContainer = strContainer & strDNSDomain

set objOU =GetObject("LDAP://" & strContainer )
intCounter = 0
For each objUser in objOU
If objUser.class="user" then
objUser.SetPassword strPassword
objUser.SetInfo

objUser.Put "pwdLastSet", intPwdValue
objUser.SetInfo

objUser.Put "userAccountControl", intAccValue
objUser.SetInfo
intCounter = intCounter +1
strLastUser = objUser.Get ("name")
End if
next

WScript.Echo strPassword & " is Password. UserAccountValue = " _
& intAccValue
WScript.Quit

'  End of Script

http://www.computerperformance.co.uk/ezine/ezine50.htm
neo_joel
hehe my friend actually tested a script like this at home and he set it to 5 million user accounts just to see if his box would handle it and it did laugh.gif , can u imagine, 5 million user accounts hehe.. he is now going for 10 million. He told me this morning that his cpu usage has been at 100% for the past 12 hours creating those objects in AD, i found it quite humorous myself. tongue.gif
Sleeper
will this work for just local accounts on a 2003 Server as it is only in a workgroup
Joel
Quote - (Sleeper @ Nov 29 2004, 10:57)
will this work for just local accounts on a 2003 Server as it is only in a workgroup
[snapback]585008629[/snapback]

See now, you never mentioned that. tongue.gif I doubt it.
Aaron P
Try this (I've not tested, but it should work). Save as a .VBS file.

CODE
strComputer = "."

Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("user")

For Each objUser In colAccounts
       Set objUser = GetObject("WinNT:// " & strComputer & "/" & objUser.Name")
       objUser.Put "PasswordExpired", 1
       objUser.SetInfo
Next
Sleeper
QUOTE(agenta @ Nov 30 2004, 03:18)
Try this (I've not tested, but it should work). Save as a .VBS file.

CODE

strComputer = "."

Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("user")

For Each objUser In colAccounts
    Set objUser = GetObject("WinNT:// " & strComputer & "/" & objUser.Name")
    objUser.Put "PasswordExpired", 1
    objUser.SetInfo
Next

[right][snapback]585012636[/snapback][/right]


didn't work for me sad.gif
Aaron P
What error do you get?
Sleeper
got it working biggrin.gif thanks very much.

Would it be possible to single it down to a list of users, rather than them all?
Aaron P
with a few changes you could read the list of users from a text file, or specify the username on the command line
OliverPlattner
QUOTE(agenta @ Dec 2 2004, 06:22)
with a few changes you could read the list of users from a text file, or specify the username on the command line
[right][snapback]585028209[/snapback][/right]


I tried using this script on my XP machine and it would answer: Line:7 Char:77 unterminated string constant


Anyone know why?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.