How do I Disable Multiple Computer Accounts via Script/Batch File?

John_Chambers
John_Chambers used Ask the Experts™
on
I have multiple computer accounts that have been polled as having some type of security vulnerability be it an unauthorized application, virus infection, outdated a/v definition file or etc.  I have a list of all the computer accounts but I do not know how to mass diable those computer accounts.  Can anyone shed some light on how to perform this task?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Justin DurrantSr. Engineer - Windows Server/Virtualization

Commented:
You can select them all in ADUC and then right-click > Disable
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Assuming your list contains one computer name per line, save the script below as DisabledComputers.cmd or Whatever.cmd, change ComputerList to the correct path to your computer list, and run it:

@echo off
set ComputerList=C:\Temp\BadMachines.txt
for /f "delims=" %%a in ('type "%ComputerList%"') do (
  echo Processing %%a ...
  dsquery computer -name "%%a" | dsmod computer -disabled yes
)

Open in new window

The only thing you need to put the cycle in to process multiple entries. Would you need help with this ?
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23360030.html

Author

Commented:
Thanks alot for your help.  The solution that you provided was exactly what I was looking for and was definitely easy to implement.  I was also able to take the basics of your script and tailor it to other tasks as well.  Again, much thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start Today