When you change the name of a Linux or Windows machine connected to Azure Arc-enabled servers, the new name isn’t recognized automatically because the resource name in Azure is immutable.

As with other Azure resources, you must delete the resource and re-create it in order to use the new name.

For Azure Arc-enabled servers, before you rename the machine, it’s necessary to remove the VM extensions before proceeding.

Audit and remove the VM extensions installed on the machine and note their configuration using the Azure CLI or Azure PowerShell.

Below I will use Azure PowerShell to determine the installed VM extensions.


First I will connect to my Azure Tenant and subscription where my Azure Arc enabled servers are placed to.

> Connect-AzAccount -Tenant <Tenant ID> -SubscriptionId <Subscription ID>


I will first need to install and import the Azure PowerShell module named Az.ConnectedMachine.


> Install-Module Az.ConnectedMachine
> Import-Module Az.ConnectedMachine


The following command will return my Azure Arc enabled server named Matrix-VM1 and its installed VM extensions.

> Get-AzConnectedMachineExtension -ResourceGroupName VMs -MachineName Matrix-VM1
or
> Get-AzConnectedMachineExtension -ResourceGroupName VMs -MachineName Matrix-VM1 | fl MachineExtensionType, Name


To remove an installed VM extension on your Azure Arc-enabled server we can use the Remove-AzConnectedMachineExtension cmdlet like shown below.

> Remove-AzConnectedMachineExtension -Name WindowsOsUpdateExtension -MachineName Matrix-VM1 -ResourceGroupName VMs

Source: https://learn.microsoft.com/en-us/azure/azure-arc/servers/manage-vm-extensions-powershell#list-extensions-installed


We can of course also use the Azure Portal by navigating to our Azure Arc-enabled server and the settings blade as shown below.

By clicking on it above we can next uninstall it.


The next step is to disconnect our Azure arc-enabled server from Azure Arc by using the azcmagent tool which is installed directly Azure arc-enabled server. This will delete the machine resource from Azure.

You can run this manually while logged on interactively, with a Microsoft identity access token, or with the service principal you used for onboarding (or with a new service principal that you create.

Disconnecting the machine from Azure Arc-enabled servers doesn’t remove the Connected Machine agent, and you don’t need to remove the agent as part of this process.

Source: https://learn.microsoft.com/en-us/azure/azure-arc/servers/manage-agent?tabs=windows#renaming-an-azure-arc-enabled-server-resource


The installed version of the azcmagent tool we can determine by running the following command on our Azure arc-enabled server.

> azcmagent version


To disconnect execute the following cmdlet.

>azcmagent disconnect


Finally after renaming the machine we need to re-register the Connected Machine agent with Azure Arc-enabled servers.

Run the azcmagent tool again on the Azure arc-enabled server with the Connect parameter as shown below.

The agent will default to using the computer’s current hostname, but you can choose your own resource name by passing the –resource-name parameter to the connect command.


> azcmagent connect --subscription-id [subscription] --resource-group [resourcegroup] --location [region]


Redeploy the VM extensions that were originally deployed to the machine from Azure Arc-enabled servers.


For servers you no longer want to manage with Azure Arc-enabled servers, remove any VM extensions from the server, disconnect the agent, and uninstall the software from your server. It’s important to complete all of these steps to fully remove all related software components from your system.

Source: https://learn.microsoft.com/en-us/azure/azure-arc/servers/manage-agent?tabs=windows#renaming-an-azure-arc-enabled-server-resource






Links

Managing and maintaining the Connected Machine agent
https://learn.microsoft.com/en-us/azure/azure-arc/servers/manage-agent?tabs=windows

Get-AzConnectedMachineExtension
https://learn.microsoft.com/en-us/powershell/module/az.connectedmachine/get-azconnectedmachineextension?view=azps-13.0.0

azcmagent CLI reference
https://learn.microsoft.com/en-us/azure/azure-arc/servers/azcmagent

azcmagent disconnect
https://learn.microsoft.com/en-us/azure/azure-arc/servers/azcmagent-disconnect