Submitted By: Anonymous Submission

Reads in computer names from a text file and then disables each of the corresponding computer accounts.

Visual Basic
Edit|Remove
'==========================================================================
' NAME:    DisableMachines.vbs
' AUTHOR:  Ronen Shurer
' DATE  :  02/05/2006
' COMMENT: This script will disable computer accounts on the domain
'          according to a supplied list of machines.
'==========================================================================
'Constants Declaration
	Const ForReading = 1 'For text file reading
	InputFileName = "c:\machines.txt"
	DomainString = "netbiosdomainname"
'==========================================================================
On Error Resume Next

set myFSO = CreateObject("Scripting.FileSystemObject")
set myFile = myfso.openTextFile(InputFileName, ForReading)
set DomainObj = GetObject("WinNT://" & DomainString)
Do
	strComputer = myFile.readline
	set objComputer = GetObject("LDAP://CN=" & strComputer & ",CN=Computers,DC=mydomain,DC=com")
	objComputer.AccountDisabled = True
	objComputer.SetInfo
	WScript.Echo("Disabled " & strComputer & " on Active Directory")
Loop Until myFile.AtEndOfStream
Set DomainObj = Nothing
myFile.Close