Main Page / Index

' LocalAdminPWchg.vbs
' Enumerate all the computers in the domain (OU specified below)
' Be careful this will reset the local admin password on everything
' including servers if they are within the OU "tree" specified
' Just change the LDAP tree and the new password
' Suggested usage: cscript LocalAdminPWchg.vbs > PasswordsChanged.txt 'then
' you'll have a list of the computers the script changed or missed


sLDAP = "LDAP://OU=Laptops,OU=Computers,OU=Austin,DC=ad,DC=yourdomain,DC=com"

On Error Resume Next

Set aConnection = CreateObject("ADODB.Connection")
Set aCommand = CreateObject("ADODB.Command")
aConnection.Provider = "ADsDSOObject" 
aConnection.Open    
aCommand.ActiveConnection = aConnection
'Use the "subTree" parameter if you want to search the whole tree
 aCommand.CommandText = "<" & sLDAP & ">;" _
    & "(objectClass=computer);Name;subTree"
Set aResult = aCommand.Execute()
Do While Not aResult.EOF
    strComputer = aResult.Fields("Name")
    strComputer = strComputer.CN
          IsOnline=PcOnline(strComputer)
        If IsOnline = True Then
            Set objUser = GetObject("WinNT://" & strComputer & "/Administrator, user")
            objUser.SetPassword "0ldLoca1AdminPW"
            objUser.SetInfo
        End If   
    aResult.MoveNext
Loop

Function PcOnline (strComputer)
'Check if the remote machine is online.
    Dim objPing,objStatus
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
        ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")
    For Each objStatus in objPing
        If  IsNull(objStatus.ReplySize) Then
            PcOnline=False
            Wscript.Echo strComputer & vbTab & " is NOT reset"
         Else
            PcOnline=True
            Wscript.Echo strComputer & vbTab & " is reseting"
         End If
    Next
    Set objPing=Nothing
    Set objStatus=Nothing
End Function




Document made with Nvu