Tuesday, September 14, 2010

Remotely rename computer name

This VBS script can be used to remotely rename computer name.
It is using netdom command and it is successfully tested on Windows Server 2008 R2 to rename Windows 7 machine.

Copy this text below into vbs script, modify the value for your "DOMAIN" and put your user with Domain Admin privileges;

*******************************************************
'On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")

Dim sNewCname 'Variable to hold Computer Name you enter in the inputbox
Dim sOldCname 'computers current name

'First param is message text, second is message title
sOldCname = InputBox("Enter computers current name","Windows Netdom Rename Script")
sNewCname = InputBox("Enter computers new name","Windows Netdom Rename Script")

Call WSHShell.Run("cmd.exe /K netdom renamecomputer " & sOldCname & " /newname:" & sNewCname & " /userd:DOMAIN\ADMINISTRATOR /passwordd:* /usero:DOMAIN\ADMINISTRATOR /passwordo:* /force ")

WScript.Echo "Click OK for reboot target machine"
set objWMI = GetObject("winmgmts:\\" & sOldCname & "\root\cimv2")
for each objOS in objWMI.InstancesOf("Win32_OperatingSystem")
objOS.Reboot()
next
**************************************************

Script is asking for old and new computer name, after that you should enter password for the user with Domain Admin privileges twice and click OK this machine to be rebooted remotely.

1 comment: