Discussion Locked

Scripting

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Looking for a script that will rename and change password on all of the local administrators user accounts. I can do this through GPO I know, but I want to run this particular script on a list of servers without having to reboot. I have found a couple on the internet but they did not rename the account just changed the password.

Thanks!

Blitz

3 replies

by gurzick

' Usage: cscript script.vbs computername
' For Example: cscript script.vbs servername
sComputer=ucase(wscript.arguments(0))
set objNetwork=CreateObject("Wscript.Network")
sComputer=objNetwork.ComputerName
' New Administrator Name
sNewName=""
' New Password to be set
strPassword=""

set ocomputer=GetObject("WinNT://"&sComputer)
if err.number <> 0 then
wscript.echo "Couldn't connect to " & sComputer & ". Error: " & cSTR(Hex(err.number)) & " " & err.description
err.clear
wscript.quit
end if

for each oUser in oComputer
if oUser.class="User" then
if right(GetSid(oUser.objectSID),4)="-500" then set oAdmin=ouser
if right(GetSid(oUser.objectSID),4)="-500" then oUser.SetPassword strPassword
if right(GetSid(oUser.objectSID),4)="-500" then oUser.SetInfo
end if
next

if TypeName(oAdmin) <> "Object" then
wscript.echo "Couldn't get admin account on " & sComputer & ". Error: " & cSTR(Hex(err.number)) & " " & err.description
err.clear
wscript.quit
end if

set oNew=oComputer.MoveHere (oAdmin.ADsPath,sNewName)

if err.number <> 0 then
wscript.echo "Error setting password on " & sComputer & ". Error: " & cSTR(Hex(err.number)) & " " & err.description
err.clear
end if
wscript.echo sComputer & " - done."

Function GetSid(bSID)
dim arrSubAut(25)
strSID="S"
strTmp=Cstr(hex(ascw(mid(bSid,1))))
arrSubAut(1)=CDbl(right(strTmp,2))
arrSubAut(2)=CDbl(left(strTmp,2-4+len(strTmp)))
for intx = 3 to len(bSid)/2
arrSubAut(intX)="&H"&Cstr(hex(ascw(mid(bSid,intx*2))))&CStr(hex(ascw(mid(bSid,(intx*2)-1))))
next
for intx = 1 to len(bSid)/2
strSID=strSID&"-"&CStr(CDbl(arrSubAut(intx)))
next
GetSid=strSID
End Function

This discussion is closed to new replies.