Disable computeraccounts in AD
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
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
Answers (5)
Please log in to answer
Posted by:
brenthunter2005
19 years ago
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.
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."
Posted by:
baldeagle
19 years ago
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
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
Posted by:
brenthunter2005
19 years ago
Posted by:
baldeagle
19 years ago
Posted by:
baldeagle
19 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.