'resetpasswords.vbs On Error Resume Next ' collect script info ' admin account name wscript.stdout.write "Enter the Administrator account name: " adminAccount = Wscript.StdIn.ReadLine ' admin account password Set objPassword = CreateObject("ScriptPW.Password") WScript.StdOut.Write "Enter the new Administrator password:" adminPassword = objPassword.GetPassword() ' DN of OU or Domain wscript.stdout.writeline() wscript.stdout.writeline() wscript.stdout.writeline "Enter the Distinguished Name of " &_ " the OU" wscript.stdout.write "(Example: ou=staff,dc=mcpmag,dc=com): " strDN = Wscript.StdIn.ReadLine ' create output log file set oFSO=CreateObject("Scripting.FileSystemObject") If Not oFSO.FolderExists("c:\scripts\lists") Then oFSO.CreateFolder("c:\scripts") oFSO.CreateFolder("c:\scripts\lists") End If If oFSO.FileExists("c:\scripts\lists\failed.txt") Then oFSO.DeleteFile("c:\scripts\lists\failed.txt") End If If oFSO.FileExists("c:\scripts\lists\success.txt") Then oFSO.DeleteFile("c:\scripts\lists\success.txt") End If set oFailureReport= _ oFSO.createtextfile("c:\scripts\lists\failed.txt") set oSuccessReport= _ oFSO.createtextfile("c:\scripts\lists\success.txt") ' Connect to OU and collect computer accounts Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.CommandText = _ "SELECT Name FROM 'LDAP://" & _ strDN & "' WHERE objectClass='computer'" objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 30 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst ' Output computer accounts, connect to each ' computer, and reset admin password Do Until objRecordSet.EOF strComputer = objRecordSet.Fields("Name").Value ' connect to computer set oAdminID = GetObject("WinNT://" & strComputer & _ "/" & adminAccount & ",user") 'Check for error and record in case of failed attempt If Err Then ReportError() Err.Clear Else oAdminID.SetPassword adminPassword oAdminID.SetInfo oSuccessReport.WriteLine strComputer & _ " Admin Password was reset." End If objRecordset.MoveNext Loop 'Close all open files oFailureReport.close oSuccessReport.close 'Present yourself a message so you'll know its finished wscript.echo() wscript.echo("Password reset complete!") wscript.echo("Please view the C:\scripts\lists\failures.txt") wscript.echo("and c:\scripts\lists\success.txt files") wscript.echo("to confirm that all passwords were") wscript.echo("successfully reset.") Sub ReportError() oFailureReport.WriteLine strComputer & _ " could not be reset. Check that it is powered on." & _ Err.Number End Sub