×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Disable multiple computer accounts using TXT file with computer names

Disable multiple computer accounts using TXT file with computer names

Disable multiple computer accounts using TXT file with computer names

(OP)
So I have Windows Server 2003 AD with a lot of machines and PowerShell is not an option.
I run dsquery computer comand to give me devices inctive for 104 and removed some that could not be removed due to still being in use.

I am trying to come up with a VBScript to disable the devices in a TXT file with devices names but the script errors out.

This is what I am trying to use.

CODE --> VBScript

Option Explicit

Dim strFileName, objFSO, objFile, strComputerName, objComputer
Dim arrComputerNames, intCount

' Specify the TXT file containing the list of computer names
strFileName = "C:\path\to\computers.txt"

' Read computer names from the TXT file into an array
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, 1)

Do Until objFile.AtEndOfStream
    strComputerName = Trim(objFile.ReadLine)
    If strComputerName <> "" Then
        ReDim Preserve arrComputerNames(intCount)
        arrComputerNames(intCount) = strComputerName
        intCount = intCount + 1
    End If
Loop

objFile.Close

' Bind to each computer account and disable it
For Each strComputerName In arrComputerNames
    On Error Resume Next
    Set objComputer = GetObject("LDAP://" & strComputerName)

    If Err.Number = 0 Then
        ' Check if the computer account is not already disabled
        If Not objComputer.AccountDisabled Then
            ' Disable the computer account
            objComputer.AccountDisabled = True
            objComputer.SetInfo
            WScript.Echo "Disabled computer account: " & strComputerName
        Else
            WScript.Echo "Computer account is already disabled: " & strComputerName
        End If
        Set objComputer = Nothing
    Else
        WScript.Echo "Error binding to computer account " & strComputerName & ": " & Err.Description
    End If

    On Error GoTo 0
Next

WScript.Echo "Script completed." 

My Server errors out and says:
Line:16
Char:9
Error:Type mismatch
Error Code:800A000D

Appreciate all your help

RE: Disable multiple computer accounts using TXT file with computer names

Declare arrComputerNames as array:
Dim arrComputerNames(), intCount 

combo

RE: Disable multiple computer accounts using TXT file with computer names

(OP)
So that would require the change like below?

CODE --> VBScript

Option Explicit

Dim strFileName, objFSO, objFile, strComputerName, objComputer
Dim arrComputerNames(), intCount

' Specify the TXT file containing the list of computer names
strFileName = "C:\path\to\computers.txt" 

Is there anything else I need to change?
Does this need to change as well?

CODE --> VBScript

Do Until objFile.AtEndOfStream
    strComputerName = Trim(objFile.ReadLine)
    If strComputerName <> "" Then
        ReDim Preserve arrComputerNames(intCount)
        arrComputerNames(intCount) = strComputerName
        intCount = intCount + 1
    End If
Loop 

To something like that?

CODE --> VBScript

Do Until objFile.AtEndOfStream
    strComputerName = Trim(objFile.ReadLine)
    If strComputerName <> "" Then
        ReDim Preserve arrComputerNames(intCount)
        arrComputerNames(intCount) = strComputerName
        intCount = intCount + 1
    End If
Loop 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close