An Azure service that is used to provision Windows and Linux virtual machines.
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.
- 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.