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.
  • Posts

    • Since they open sourced the calculator in Win 10/11 it is much better and can do a lot, I love it.
    • That's just silly imo. The lengths that man goes to just to avoid W11 is just nuts. Very, very few home users would do that. I will say this though, he is committed. Btw, I note on askwoody that Woody Leonhard passed away March, 2025 aged 73. His site was one of my favorites back in the day. Belated yes but RIP Woody.
    • Because of the EU (a good thing) newer android devices been getting 5 years worth of security patches. Except some Motorola which found the loop hole, and offer ZERO updates. In addition, Google for years have been making where it can patch some stuff by updating the core Google Play Store itself.  As echoed earlier,  you take the security risk in to your own hand beyond supported.
    • Win11Debloat 06.11.2026 by Razvan Serea Win11Debloat is a lightweight, easy to use PowerShell script that allows you to quickly declutter and customize your Windows experience. It can remove pre-installed bloatware apps, disable telemetry, remove intrusive interface elements and much more. The script also includes many features that system administrators and power users will enjoy. Such as a powerful command-line interface, support for Windows Audit mode and the option to make changes to other Windows users. All changes made by Win11Debloat can be easily reversed, and most removed apps can be restored via the Microsoft Store. A full guide on how to undo the changes is available here. Win11Debloat features: Below is an overview of the key features and functionality offered by Win11Debloat. Please refer to the wiki for more information about the default settings preset. Remove a wide variety of preinstalled apps. Click here for more info. Disable telemetry, diagnostic data, activity history, app-launch tracking & targeted ads. Disable tips, tricks, suggestions & ads across Windows. Disable Windows location services & app location access. Disable Find My Device location tracking. Disable 'Windows Spotlight' and tips & tricks on the lock screen. Disable 'Windows Spotlight' desktop background option. Disable ads, suggestions and the MSN news feed in Microsoft Edge. Hide Microsoft 365 ads on the Settings 'Home' page, or hide the 'Home' page entirely. Disable & remove Microsoft Copilot. Disable Windows Recall. Disable Click to Do, AI text & image analysis tool. Prevent AI service (WSAIFabricSvc) from starting automatically. Disable AI Features in Edge. Disable AI Features in Paint. Disable AI Features in Notepad. Disable the Drag Tray for sharing & moving files. Restore the old Windows 10 style context menu. Turn off Enhance Pointer Precision, also known as mouse acceleration. Disable the Sticky Keys keyboard shortcut. Disable Storage Sense automatic disk cleanup. Disable fast start-up to ensure a full shutdown. ...and more. Once you’ve downloaded the Win11Debloat file (Get.ps1), just follow these quick steps: Locate the Get.ps1 script file. Right-click the file and select Run with PowerShell from the context menu. If prompted by User Account Control (UAC), select Yes to grant the script the necessary administrative permissions. Win11Debloat 06.11.2026 fixes: Fix lock screen spotlight option being disabled when disabling the start recommended section by @Raphire in #619 Fix log message formatting by @Raphire Note The -RemoveCommApps and -RemoveW11Outlook command-line parameters for uninstalling a few specific apps have been removed with this release. If you previously relied on these parameters, please see this wiki page for alternative methods of removing these apps. Download: Win11Debloat 06.11.2026 | Open Source View: Win11Debloat Home Page | Screenshots 1| 2 Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Rookie
      restore went up a rank
      Rookie
    • Very Popular
      AndrewSteel earned a badge
      Very Popular
    • Veteran
      Taliseian went up a rank
      Veteran
    • One Month Later
      Clizby earned a badge
      One Month Later
    • One Month Later
      Timaximus earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      502
    2. 2
      +Edouard
      162
    3. 3
      PsYcHoKiLLa
      154
    4. 4
      ATLien_0
      83
    5. 5
      Steven P.
      79
  • Tell a friend

    Love Neowin? Tell a friend!