Create Accounts from Command Line


Recommended Posts

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.

Link to comment
https://www.neowin.net/forum/topic/250496-create-accounts-from-command-line/
Share on other sites

PwdLastSet.vbs

' 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

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: , 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. :p

Try this (I've not tested, but it should work). Save as a .VBS file.

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

Try this (I've not tested, but it should work). Save as a .VBS file.

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

585012636[/snapback]

didn't work f:( me :(

  • 3 weeks later...
with a few changes you could read the list of users from a text file, or specify the username on the command line

585028209[/snapback]

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

Anyone know why?

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.