Delete local accounts in windows using cmd script

Viewed 24

Hello I created simple script to remove windows local users.

@echo off
set /p username= Enter the name of account which you want to delete : 
net user /DELETE %username%
pause

The only problem is if the users are many I need to run the script for each user again and again. I need to make it working with many users. When cmd prompt me about name I should be able to enter them with comma or just single space, collect them in array, later delete them with foreach or some loop function. How to make it with cmd?

1 Answers

Thanks to Compo the script is working perfect (run as administrator)

@Set /P "UserNames=Enter the account names for deletion: "
@For %%G In (%UserNames%) Do @%SystemRoot%\System32\net.exe User %%G /Delete
Related