Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I’m on a Windows 2008 server and would like to delete 15 users (user1 till user15) without having to do this by hand.

After deleting them completely I’d like to readd them (again, with a script) and give all of them the same password for which the script should ask for.

Any help (hints, complete script) is appreciated.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can use the "net user" command to add and delete accounts.

Here is a generic batch file that will LOOP:

@echo off

set i=%1
set j=%2

set /a j = %i% + %2

@echo start, i = %I% and j = %J%

if %i% GTR %j% goto FINISHED
echo i = %i%
set /a i=%i + 1
goto LOOP

@echo finished, i = %I%
goto END

@echo Usage   : loop.bat [ start # ] [ # of iterations ]
@echo Example : loop.bat 4 5   (this will start at 4 and end at 9)
goto END


In the loop you would need to do two things:

  • net user /delete user%I%
  • net user /add user%I% (with more options)

You can modifiy the batch file to take a third argument which could be the password that is then passed on to the "net user /add" command.

Use "net help user" to get more information on how to use the command.

share|improve this answer
Wow, that was fast :-). Will try in a few minutes. Thanks so much. – Ulf Klose Aug 27 '10 at 15:59
Works like a charm. Thank you so much. – Ulf Klose Aug 28 '10 at 21:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.