Share via

Best practice for renaming azure virtual machine

Eric Andrade 20 Reputation points
2026-03-12T17:31:53.93+00:00

Hello,

I'm looking to change the name of my azure virtual machine, but I'm looking for guidance on the best practice for migrating my managed OS disk and network to the replacement azure virtual machine. Can someone provide a step by step process for this managed OS disk migration?

Thank you!

Azure Virtual Machines
Azure Virtual Machines

An Azure service that is used to provision Windows and Linux virtual machines.

0 comments No comments
{count} votes

Answer accepted by question author
  1. Jilakara Hemalatha 10,365 Reputation points Microsoft External Staff Moderator
    2026-03-12T18:48:42.3+00:00

    Hello

    Thank you for reaching out Q/A. In Azure virtual machine resource cannot be renamed after it has been deployed. Because of this limitation, the recommended approach is to recreate the VM with the desired name and reuse the existing managed OS disk and networking components.

    Below is a commonly used step-by-step process for recreating the VM while preserving the managed OS disk and network configuration.

    Before you begin, make sure you have:

    A snapshot or backup of the OS disk (recommended as a precaution)

    The VM’s current configuration noted, such as VM size, region, availability zone or availability set, NIC(s), tags, and disk SKU

    A maintenance window planned, as the VM will be offline during this process

    The general idea is to stop the existing VM, preserve the managed disks and network interface, remove only the VM compute resource, and then create a new VM with the desired name while attaching the existing OS disk and NIC.

    1. Deallocate the existing VM

    In the Azure Portal, navigate to your VM and click Stop. Wait until the status shows Stopped (Deallocated). It is important that the VM is deallocated from the Azure side; shutting it down from inside the operating system is not sufficient.

    2.Snapshot the OS Disk (recommended)

    Navigate to the OS disk resource associated with the VM and select Create Snapshot. this serves as a safety measure so that you can recover the disk if something goes wrong during the process.

    3.Delete VM resource only:

    Go to the VM and select Delete. When prompted, make sure the options to delete the OS disk, data disks, and network interface are not selected.

    This step removes only the VM compute resource while preserving the existing managed disks and networking components.

    4.Create the new VM with the desired name

    Create a new virtual machine in the Azure portal using the new VM name. Ensure that you select the same region and VM size if you want to maintain the same configuration.

    During the creation process, go to the Disks section and choose Attach an existing disk, then select the OS disk that was used by the previous VM.

    5.Attach the existing network interface

    In the Networking section of the VM creation process, choose Use existing network interface and select the NIC that was previously associated with the VM.

    This allows the new VM to retain the same networking configuration, including the existing private IP, public IP (if applicable), and network security group settings.

    6.Start the new VM and validate functionality

    Once the deployment is complete, start the new VM and verify that you can connect to it (RDP or SSH). Confirm that applications, services, and networking behave as expected. After validation, any temporary snapshots that were created can be removed if they are no longer required.

    Reference thread: https://learn.microsoft.com/en-us/answers/questions/2139697/how-to-rename-an-azure-sql-vm-and-managed-disks-wi

    Reference documentations:

    Create a VM from a specialized disk using PowerShell

    Add network interfaces to or remove network interfaces from virtual machines

    Change the OS disk used by an Azure VM using PowerShell

    Hope this helps! Please let me know if you have any queries.

    You found this answer helpful.
    0 comments No comments

Answer accepted by question author
  1. Marcin Policht 82,360 Reputation points MVP Volunteer Moderator
    2026-03-12T18:40:00.55+00:00

    As I gather you already know, in Azure you cannot rename an existing virtual machine resource. To work around it, create a new VM resource with the desired name and attach the existing managed OS disk. This preserves the operating system, configuration, and installed software. The overall process is to deallocate the existing VM, detach and preserve its managed OS disk and networking configuration, delete the VM resource while keeping the disks and NIC, and then create a new VM using the existing OS disk and existing network interface.

    Start by stopping and deallocating the existing virtual machine. This ensures Azure releases the compute resource but leaves the disks intact.

    az vm deallocate --resource-group <resource-group> --name <old-vm-name>
    

    Verify the VM is deallocated.

    az vm get-instance-view --resource-group <resource-group> --name <old-vm-name> --query instanceView.statuses
    

    Identify the OS disk name and the network interface associated with the VM.

    az vm show --resource-group <resource-group> --name <old-vm-name> --query "storageProfile.osDisk.name" -o tsv
    az vm show --resource-group <resource-group> --name <old-vm-name> --query "networkProfile.networkInterfaces[0].id" -o tsv
    

    If you want to reuse the same NIC and therefore keep the same private IP configuration, confirm that the VM is fully deallocated. Then delete the VM resource but keep the disks and network interface. Azure only removes the compute resource.

    az vm delete --resource-group <resource-group> --name <old-vm-name> --yes
    

    Confirm that the managed OS disk and NIC still exist.

    az disk show --resource-group <resource-group> --name <os-disk-name>
    az network nic show --ids <nic-id>
    

    Now create the replacement VM with the new name using the existing OS disk and existing NIC. When creating from an existing OS disk you must specify the OS type.

    az vm create \
      --resource-group <resource-group> \
      --name <new-vm-name> \
      --attach-os-disk <os-disk-name> \
      --os-type <Linux|Windows> \
      --nics <nic-id>
    

    If the VM previously had data disks attached, reattach them as well.

    az vm disk attach \
      --resource-group <resource-group> \
      --vm-name <new-vm-name> \
      --name <data-disk-name>
    

    Once the VM is created, start it.

    az vm start --resource-group <resource-group> --name <new-vm-name>
    

    This preserves the managed disk and networking resources while only replacing the compute resource. It also avoids OS reinstallation and maintains the original private IP address if the same NIC is reused. If the VM uses a public IP resource attached to the NIC, that address will remain unchanged as well since the NIC is reused. The only change in Azure Resource Manager will be the virtual machine resource name.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.