Remotely Rename A Computer

Remotely rename a computer and its Active Directory account using PSExec and batch file (vbs dropper)

Usage: PSExec.exe \\CURRENTCOMPUTERNAME -c -d -f RenameComputer.bat NEWCOMPUTERNAME
(Account needs Admin on target computer and modify rights on computer object in AD)

RenameComputer.bat

@ECHO OFF
ECHO Option Explicit > RenameComputer.vbs
ECHO. >> RenameComputer.vbs
ECHO On Error Resume Next >> RenameComputer.vbs
ECHO. >> RenameComputer.vbs
ECHO Dim objWMIService >> RenameComputer.vbs
ECHO Dim colComputers >> RenameComputer.vbs
ECHO Dim objComputer >> RenameComputer.vbs
ECHO Dim varError >> RenameComputer.vbs
ECHO. >> RenameComputer.vbs
ECHO Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >> RenameComputer.vbs
ECHO. >> RenameComputer.vbs
ECHO Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem") >> RenameComputer.vbs
ECHO. >> RenameComputer.vbs
ECHO For Each objComputer in colComputers >> RenameComputer.vbs
ECHO     varError = objComputer.Rename("%1") >> RenameComputer.vbs
ECHO Next >> RenameComputer.vbs
ECHO WScript.Echo varError >> RenameComputer.vbs

CScript //NOLOGO RenameComputer.vbs
DEL RenameComputer.vbs

Shutdown -r -f -t 60

Leave a Reply

Your email address will not be published. Required fields are marked *