Kaseya Community

Yet another rename script

  • For those of you who may find it useful; here is a script I use to rename a PC that is NOT part of a domain. I use it to rename PCs before adding them to a domain.

    Script Name: Rename PC
    Script Description: This script will rename the computer and then force a reboot.


    IF Test File
    Parameter 1 : c:\KaseyaTemp\RenameWKGpc.vbs
    Exists :
    THEN
    Execute File
    Parameter 1 : %windir%\system32\cscript.exe
    Parameter 2 : c:\KaseyaTemp\RenameWKGpc.vbs
    Parameter 3 : 3
    OS Type : 0
    Send Message
    Parameter 1 : Your computer has been renamed.
    Parameter 2 : 1
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : **The computer has been renamed.**
    OS Type : 0
    Execute Shell Command
    Parameter 1 : shutdown -r -t 01
    Parameter 2 : 1
    OS Type : 0
    ELSE
    Write File
    Parameter 1 : c:\KaseyaTemp\RenameWKGpc.vbs
    Parameter 2 : VSASharedFiles\RenameWKGpc.vbs
    OS Type : 0
    Execute File
    Parameter 1 : %windir%\system32\cscript.exe
    Parameter 2 : c:\KaseyaTemp\RenameWKGpc.vbs
    Parameter 3 : 3
    OS Type : 0
    Send Message
    Parameter 1 : Your computer has been renamed.
    Parameter 2 : 1
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : **The computer has been renamed.**
    OS Type : 0
    Execute Shell Command
    Parameter 1 : shutdown -r -t 01
    Parameter 2 : 1
    OS Type : 0


    VB Script (RenameWKGpc.vbs):

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
    Set colComputers = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
    For Each objComputer in colComputers
    errReturn = ObjComputer.Rename("NewTESTName")
    WScript.Echo "Computer name is now " & objComputer.Name
    Next

    Legacy Forum Name: Yet another rename script,
    Legacy Posted By Username: pbrophy
  • Here is a script I use to rename a PC that is already ON a domain. Remember to make the appropriate changes:
    OLDNAME, NEWNAME, ADMIN, PASSWORD.

    I also have a reboot script that it calls in the later steps that I haven't provided. I'm sure you guys can handle that.
    ; )



    Script Name: Rename Computer
    Script Description: This script will rename a computer in a domain and then reboot the computer after 2 min.

    PC needs to be joined to a domain first.

    IF Test File
    Parameter 1 : c:\windows\system32\netdom.exe
    Exists :
    THEN
    Execute Shell Command
    Parameter 1 : netdom renamecomputer OLDNAME /NewName:NEWNAME /UserDBig SmileOMAIN\ADMIN /PasswordDStick out tongueASSWORD /force
    Parameter 2 : 1
    OS Type : 0
    Send Message
    Parameter 1 : Your computer has been renamed, to finish this process your computer will reboot in 2 minutes. Please save all documents.
    Parameter 2 : 1
    OS Type : 0
    Pause Script
    Parameter 1 : 120
    OS Type : 0
    Execute Script
    Parameter 1 : System Restart (NOTE: Script reference is NOT imported. Correct manually in script editor.
    Parameter 2 :
    Parameter 3 : 0
    OS Type : 0
    ELSE
    Execute Script
    Parameter 1 : Netdom.exe Install (NOTE: Script reference is NOT imported. Correct manually in script editor.
    Parameter 2 :
    Parameter 3 : 0
    OS Type : 0
    Pause Script
    Parameter 1 : 60
    OS Type : 0
    Execute Shell Command
    Parameter 1 : netdom renamecomputer OLDNAME /NewName:NEWNAME /UserDBig SmileOMAIN\ADMIN /PasswordDStick out tongueASSWORD /force
    Parameter 2 : 1
    OS Type : 0
    Send Message
    Parameter 1 : Your computer has been renamed, to finish this process your computer will reboot in 2 minutes. Please save all documents.
    Parameter 2 : 1
    OS Type : 0
    Pause Script
    Parameter 1 : 120
    OS Type : 0
    Execute Script
    Parameter 1 : System Restart (NOTE: Script reference is NOT imported. Correct manually in script editor.
    Parameter 2 :
    Parameter 3 : 0
    OS Type : 0

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: pbrophy
  • Is there a way to have the script reference a txt file in order to be able to rename MULTIPLE machines rather than having to change the script for each computer?

  • You would need to use PowerShell or VBscript to do that, I prefer to use PowerShell for Vista/7/2008 and VBscript for older Windows OS's instead of NETDOM because not all computers have it installed and finding the correct one for the version of Windows is to much effort.

  • I'm going to use the new "Get Variable/Promt for variable" function in the Precedure module.