Rename Computer

Table of Contents

Here is a script to rename the computer
Make sure you add /NewName:YourNewComputerName in the script parameters and obviously change it for your naming.
Also note that each computer requires a unique name on the network to prevent conflicts so ensure the new name is unique.

strComputerName = WScript.Arguments.Named("NewName")

If strComputerName  "" then
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery ("Select Name from Win32_ComputerSystem")

For Each objComputer in colComputers
    wscript.echo "Old Computer Name: " & objComputer.Name
    wscript.echo "New Computer Name: " & strNewName

    If objComputer.Name  strNewName Then

       ' rename this computer

       intErrorCode = objComputer.Rename(strComputerName)
       ' now reboot
       Reboot
    End if
Next
Else
wscript.echo "Please define a computer name!"
End If
Sub Reboot()

dim strComputer, objWMIService, colOS, objOS
  strComputer = "."

  Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
  Set colOS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

  For Each objOS in colOS
                objOS.Reboot()
  Next
End Sub

Our Services