/build/static/layout/Breadcrumb_cap_w.png

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

0 Comments   [ + ] Show comments

Answers (5)

Posted by: brenthunter2005 19 years ago
Fifth Degree Brown Belt
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."
Posted by: baldeagle 19 years ago
Senior Yellow Belt
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
Posted by: brenthunter2005 19 years ago
Fifth Degree Brown Belt
0
Sorry. Looking at the code you need to change that line to read:

strComputerName = objSheet.Cells(intStartRow, 1).Value
Posted by: baldeagle 19 years ago
Senior Yellow Belt
0
Thx,

I also found what the problem was. It worked great and saved me hours.
Posted by: baldeagle 19 years ago
Senior Yellow Belt
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ