Do more with
On Error Next
Dim StrComp
'************************************************************************************
'Creates a Connection Object for connection to AD
'************************************************************************************
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
'************************************************************************************
'Opens the text file for reading
'************************************************************************************
set myFSO = CreateObject("Scripting.FileSystemObject")
set myFile = myfso.openTextFile("\\flhlaw.local\userdata\Folders\BOSCAM\Documents\Computername.txt", 1)
Do
'************************************************************************************
'Starts to read line by line
'************************************************************************************
strComp = myfile.Readline
'************************************************************************************
'Connecting to Active Directory
'************************************************************************************
objConnection.Provider = "ADSDSOObject"
objConnection.Open ""
'************************************************************************************
'Get the Root DSE from a random DC
'************************************************************************************
Set objRootDSE = GetObject("LDAP://RootDSE")
'************************************************************************************
'Connect to the schema container on a random DC
'************************************************************************************
strDNSDomain = objRootDSE.Get("defaultNamingContext")
Set StrDC = GetObject("LDAP://" & StrDNSDomain)
StrServices = Ucase(StrDC.DC)
'************************************************************************************
'Searches AD for the computer name and returns the LDAP DN
'************************************************************************************
Set objRS = objConnection.Execute("<LDAP://" & StrDNSDomain & ">;(&(&(&(objectCategory=computer)(objectClass=computer)(Name=" & strComp &"))));Name,ADsPath;SubTree")
While Not objRS.EOF
strName = objRS.Fields.Item("Name").Value
strADs = objRS.Fields.Item("ADsPath").Value
'************************************************************************************
'Connects to the Computer Object and disables it
'************************************************************************************
set objComputer = GetObject(StrADs)
objComputer.AccountDisabled = True
objComputer.SetInfo
WScript.Echo("Disabled " & strComputer & " on Active Directory")
objRS.MoveNext
Wend
set objRS = Nothing
objConnection.Close
Loop Until Myfile.AtEndOfStream
MyFile.close
Premium Content
You need an Expert Office subscription to comment.Start Free Trial