Hi,

I've got an excel sheet with a number off computeraccounts. i'd like to disable all these computeraccounts in active directory (not delete). Any suggestions how i can script this.

Thx for helping
BaldEagle
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

2
You got me in a good mood. This script will take an Excel spreadsheet (filled with computer names in the first column), connect to the LDAP path, and disable the computer account.

Good luck.



strDomain = InputBox("Enter in domain name",,"DOMAIN")
strExcelPath = InputBox("Enter in full path to Excel spreadsheet",,"C:\ComputerAccounts.xls")

On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If Err.Number <> 0 Then
wscript.Echo "DEBUG:: Excel application not found. Script will exit."
wscript.Quit
End If
On Error GoTo 0

objExcel.WorkBooks.Open strExcelPath
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)


intStartRow = 1

'Loop through each row in spreadsheet until the cell value equals nothing.
Do While objSheet.Cells(intStartRow, 1).Value <> ""

strComputerName = objSheet.Cells(intRow, 1).Value
Set objNameTranslater = CreateObject("NameTranslate")
objNameTranslater.Init 3, ""
objNameTranslater.Set 3, strDomain & "\" & strComputerName & "$"
strComputerLDAPPath = objNameTranslater.Get(1)
Set objComputer = GetObject("LDAP://" & strComputerLDAPPath)

If objComputer.AccountDisabled = TRUE then
WScript.Echo "DEBUG:: Account for " & objComputer.Get("cn") & " already disabled."
Else
objComputer.AccountDisabled = TRUE
objComputer.SetInfo
WScript.Echo "DEBUG:: Account for " & objComputer.Get("cn") & " is disabled"
End If

Set objNameTranslater = Nothing
Set objComputer = Nothing
intStartRow = intStartRow + 1

Loop


' Close workbook and quit Excel.
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit

Set objNameTranslater = Nothing
Set objExcel = Nothing
Set objComputer = Nothing

wscript.echo "Script Completed."
Answered 11/14/2005 by: brenthunter2005
Fifth Degree Brown Belt

Please log in to comment
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Thx for this great script. I hope you're in a good mood today also as i still have a small problem. I tried it on my 2000 and XP client using Off2000 and Off2003.

It works perfect as long as i don't use the excel functions. when i run in using the excel i've an "Unknown runtime error on "strComputerName = objSheet.Cells(intRow, 1).Value"

I now changed intRow to intStartRow and maybe it's solved then. I'll test it tomorrow when I'm back @ work.

Thx

Already many thx
BaldEagle
Answered 11/15/2005 by: baldeagle
Senior Yellow Belt

Please log in to comment
0
Sorry. Looking at the code you need to change that line to read:

strComputerName = objSheet.Cells(intStartRow, 1).Value
Answered 11/15/2005 by: brenthunter2005
Fifth Degree Brown Belt

Please log in to comment
0
Thx,

I also found what the problem was. It worked great and saved me hours.
Answered 11/19/2005 by: baldeagle
Senior Yellow Belt

Please log in to comment
0
Hi,

Is their a way that i can change this script so that i can read from AD the disabled accounts and save this result into an XLS file.

Thx
Answered 11/24/2005 by: baldeagle
Senior Yellow Belt

Please log in to comment
Answer this question or Comment on this question for clarity