Kaseya Community

Trouble with PC Rename Script, please help

  • I am developing a rename script that will rename a PC to "brav-%servicetag%" (brav being interchangeable with each company we support we have a abbreviated name we use). Here is the script below that I am using.

    Script Name: Rename PC - Bravura
    Script Description: Renamed PC to "brav-%servicetag%"

    IF True
    THEN
    Impersonate User
    Parameter 1 : administrator
    Parameter 2 : CoveredPwd::F4DE91581A7E8C85
    Parameter 3 : bravnet.org
    OS Type : 8
    Write File
    Parameter 1 : #vAgentConfiguration.agentTempDir#\dellst.vbs
    Parameter 2 : VSASharedFiles\Script Files\PC Rename Scripts\dellST.vbs
    OS Type : 8
    Execute Shell Command
    Parameter 1 : cscript #vAgentConfiguration.agentTempDir#\dellst.vbs
    Parameter 2 : 0
    OS Type : 8
    Pause Script
    Parameter 1 : 10
    OS Type : 8
    Get Variable
    Parameter 1 : 1
    Parameter 2 : c:\dellst.txt
    Parameter 3 : dellst
    OS Type : 8
    Execute Shell Command
    Parameter 1 : wmic ComputerSystem Where Name="%COMPUTERNAME%" Rename Name="brav-#dellst#"
    Parameter 2 : 0
    OS Type : 8
    ELSE



    The only part of the script not working is in the

    Rename Name="brav-#dellst#"

    I have tested this script in the following formats, here is the results of each

    Rename Name="brav#dellst#" (works, names PC, but missing hyphen)
    Rename Name="brav-#dellst#" (doesn't work, doesn't rename PC at all)
    Rename Name="brav--#dellst#" (works, renames PC with 2 hyphens)
    Rename Name=brav-#dellst# (doesn't work, doesn't rename PC at all)

    Anyone have any info as to why it wouldn't work with 1 hyphen but would work with 2? Would love to get this working today.

    Here is the contents of the VBS if anyone is interested.

    strComputer = "."
    set objFSO = CreateObject("Scripting.FileSystemObject")
    set objOutputFile = objFSO.CreateTextFile("C:\dellst.txt")
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colSMBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_SystemEnclosure")
    For Each objSMBIOS in colSMBIOS
    objOutputFile.WriteLine objSMBIOS.SerialNumber
    Next


    Legacy Forum Name: Trouble with PC Rename Script, please help,
    Legacy Posted By Username: djennings
  • I've got a similar script to rename workstations but using the netdom command that has the same naming scheme of client-#variable# and don't have an issue with the hyphen.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: cnwicsurrett
  • Could you post your script, or just the netdom command line so i could try that on my script?

    Thanks,
    Daryl J

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: djennings
  • I use a managed variable called for all the client abbreviations. The workstation must have Windows Support Tools/netdom command installed for this script to work.

    IF True
    THEN
    Get Variable
    Parameter 1 : 0
    Parameter 2 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname
    Parameter 3 : HostName
    OS Type : 0
    Get Variable
    Parameter 1 : 0
    Parameter 2 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Domain
    Parameter 3 : DomainName
    OS Type : 0
    Get Variable
    Parameter 1 : 0
    Parameter 2 : HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\WinLogon\DefaultUserName
    Parameter 3 : UserName
    OS Type : 0
    Use Credential
    OS Type : 0
    Execute Shell Command
    Parameter 1 : netdom renamecomputer #HostName# /newname:-#UserName# /userd:#DomainName#\username /passwordd:yourpassword /usero:#DomainName#\username /passwordo:yourpassword /force
    Parameter 2 : 1
    OS Type : 0
    Reboot
    OS Type : 0
    ELSE

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: cnwicsurrett
  • I have a similar script, done in VB. It opens a text file containing the old name and the new name (format: oldname,newname), and then it compares the computer name with oldname. If there's a match, then it renames the computer using the newname from the file.

    The kaseya script simply copies the necessary files from a central location to the local computer, then executes the script.


    dim WshNetwork
    dim ComputerName
    dim objFSO
    dim objTextFile
    dim Datafile

    Datafile = "c:\path\computernames.txt"
    Const ReadOnly = 1

    Set WshNetwork = WScript.CreateObject("WScript.Network")
    ComputerName = UCASE(WshNetwork.ComputerName)

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile (Datafile, ReadOnly)

    ' Lets read the file
    Do until objTextFile.AtEndOfStream
    strNextLine = objTextFile.ReadLine
    cNames = Split(strNextLine, ",")

    if UCASE(cNames(0)) = ComputerName then

    strCommand = "c:\path\netdom.exe renamecomputer " & ComputerName & " "
    strCommand = StrCommand & "/newname:" & UCASE(cNames(1)) & " "
    strCommand = strCommand & "/force /reboot:60 /userdBig Smileomain\userid "
    strCommand = StrCommand & "/useroBig Smileomain\userid "
    strCommand = StrCommand & "/passworddStick out tongueassword /passwordoStick out tongueassword"

    set OWS = WScript.CreateObject("WScript.shell")
    OWS.Run strCommand
    Exit Do

    end if
    Loop


    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Lmhansen