Wednesday, July 28

Reset Local Administrator Password Remotely


Recently, I got an opportunity to reset the local administrator password of all of our Citrix Servers globally. We are managing these Citrix servers geographically within sub OUs and attached script worked for me like a charm. It will traverse through all the Citrix servers with in an OU and log an entry against them. Simple - just change the password and OU, DC in this VB script according to your need.


On Error Resume Next
Err.Clear
   
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = createObject("wscript.shell")
Const  LogFolder = "C:\logs"
Const LogFile = "file1.txt"

Const SUCCESS = 0

sUser = "Administrator"
sPwd = "yourpassword here"

Set objOU = GetObject("LDAP://OU=subou,OU=Servers,DC=myDC,DC=com")
objOU.Filter = Array("Computer")

For Each objItem in objOU
'    Wscript.Echo objItem.CN
        sComputerName = objItem.CN
    Set oUser = GetObject("WinNT://" & sComputerName & "/" & sUser)

' Set the password
oUser.SetPassword sPwd
oUser.Setinfo

'Log start'
    LogFilePath = LogFolder & "\" & LogFile
    Set objLOGFile = objFSO.CreateTextFile(LogFilePath)
    objLOGFile.writeline"Password changed::"& sComputerName

if  Err.Number <> 0  then  

    objLOGFile.writeline "" & vbCrLf & "Error number: " & Err.Number & vbCrLf &_
        "Error description: '" & Err.Description & vbCrLf
End if
Next

No comments:

Post a Comment