Kaseya Community

Change machine name via procedure

  • Has anyone been able to create a procedure to change a Domain-Joined PC's name with a procedure? 

  • The only way you can do that is if you put a domain admin account username and password in the procedure... which is plain text... which is a very bad thing to do.

  • I haven't used this in a while but have done this with the "useCredential" command as our agents have an admin account entered, then using "getVariable" I ask the tech enter the new name into a variable which is then passed to a wmic command to make the change.  It must be done one PC at a time. A reboot is needed after the name change.  

    The wmic command is this:

    wmic.exe ComputerSystem Where Name="%COMPUTERNAME%" Rename Name="new_name"

    Hope this helps or sparks some more elegant way of doing this.  

  • i have built a procedure here with which i put a prefix in front of a computer name. you have to adapt it for your purposes. The script checks if the prefix is already set, if not the computer is renamed.

    <ScriptExport xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema" xmlns="www.kaseya.com/.../Scripting">

    <Procedure name="Rename Computer" treePres="3" id="1531177991" folderId="307740392865492" treeFullPath="EXITSYS.Workstation Management">

    <Body description="">

    <Statement name="GetVariable" continueOnFail="false">

    <Parameter xsi:type="EnumParameter" name="VariableType" value="Prompt"/>

    <Parameter xsi:type="StringParameter" name="SourceContent" value="Bitte Prefix eingeben (ohne Bindestrich)"/>

    <Parameter xsi:type="StringParameter" name="VariableName" value="Computername_Prefix"/>

    </Statement>

    <Statement name="ExecuteShellCommand" continueOnFail="false">

    <Parameter xsi:type="StringParameter" name="Command" value="echo $oldcomputername = $env:computername>>#vAgentConfiguration.agentTempDir#\Rename_Computer.ps1"/>

    <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="User"/>

    <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False"/>

    </Statement>

    <Statement name="ExecuteShellCommand" continueOnFail="false">

    <Parameter xsi:type="StringParameter" name="Command" value="echo if(!($oldcomputername -match "#Computername_Prefix#")){>>>>#vAgentConfiguration.agentTempDir#\Rename_Computer.ps1"/>

    <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="User"/>

    <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False"/>

    </Statement>

    <Statement name="ExecuteShellCommand" continueOnFail="false">

    <Parameter xsi:type="StringParameter" name="Command" value="echo $newcomputername = "#Computername_Prefix#-" + $oldcomputername>>>>#vAgentConfiguration.agentTempDir#\Rename_Computer.ps1"/>

    <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="User"/>

    <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False"/>

    </Statement>

    <Statement name="ExecuteShellCommand" continueOnFail="false">

    <Parameter xsi:type="StringParameter" name="Command" value="echo Rename-Computer -ComputerName $oldcomputername -NewName $newcomputername>>>>#vAgentConfiguration.agentTempDir#\Rename_Computer.ps1"/>

    <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="User"/>

    <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False"/>

    </Statement>

    <Statement name="ExecuteShellCommand" continueOnFail="false">

    <Parameter xsi:type="StringParameter" name="Command" value="echo }>>>>#vAgentConfiguration.agentTempDir#\Rename_Computer.ps1"/>

    <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="User"/>

    <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False"/>

    </Statement>

    <Statement name="UseCredential" continueOnFail="false"/>

    <Statement name="Execute Powershell Command (64-bit, Run As User)" continueOnFail="false" osType="Windows">

    <Parameter xsi:type="StringParameter" name="Parameter1" value=""/>

    <Parameter xsi:type="StringParameter" name="Parameter2" value="#vAgentConfiguration.agentTempDir#\Rename_Computer.ps1"/>

    <Parameter xsi:type="StringParameter" name="Parameter3" value="True"/>

    </Statement>

    <Statement name="DeleteFile" continueOnFail="false">

    <Parameter xsi:type="StringParameter" name="Path" value="#vAgentConfiguration.agentTempDir#\Rename_Computer.ps1_"/>

    </Statement>

    <Statement name="WriteScriptLogEntry" continueOnFail="false">

    <Parameter xsi:type="StringParameter" name="Comment" value="#global:psresult#"/>

    </Statement>

    </Body>

    </Procedure>

    </ScriptExport>