When migrating VMs between Azure subscriptions using PowerShell (as described in Microsoft's documentation), the VM's display name in the Azure portal remains unchanged from the original instance. This is different from modifying the hostname within the OS itself. The portal name is a metadata property managed by Azure's control plane.
Changing the hostname inside the VM (via sysdm.cpl or hostnamectl) only affects the operating system's identification. The Azure portal displays the Name
property from the VM resource object in Azure Resource Manager (ARM), which persists across migrations.
The most efficient method is using the Update-AzVM
cmdlet after modifying the VM object's properties:
# Get the VM object
$vm = Get-AzVM -ResourceGroupName "YourRG" -Name "OldVMName"
# Update the name property
$vm.Name = "NewVMName"
# Commit changes (this doesn't require VM restart)
Update-AzVM -ResourceGroupName "YourRG" -VM $vm -Name "OldVMName"
For those preferring Azure CLI, use this sequence:
# Get VM JSON configuration
az vm show -n OldVMName -g YourRG --query "" > vmconfig.json
# Edit the name field in JSON
sed -i 's/"OldVMName"/"NewVMName"/g' vmconfig.json
# Update the VM
az vm update --resource-group YourRG --name OldVMName --set "" --parameters @vmconfig.json
- This changes only the portal display name, not the actual hostname inside the VM
- DNS names and internal references might still use the original name
- Update operations typically take 1-2 minutes to propagate
After execution, check the portal or verify with:
Get-AzVM -ResourceGroupName "YourRG" -Name "NewVMName" | Select-Object Name
In rare cases where the name is tied to immutable resources (like certain legacy cloud services), you may need to:
- Create a new VM with the desired name
- Attach the existing VHD
- Update network configurations
When you migrate an Azure VM between subscriptions using PowerShell (as described in the Microsoft MVP guide), you'll notice the original VM name persists in the Azure portal's resource list. This isn't just a display name - it's the actual resource-level name assigned during creation.
Changing the hostname inside the VM only modifies the operating system's identification. The Azure resource name is a separate property managed at the Azure Resource Manager (ARM) level. This explains why your hostname change didn't propagate to the portal view.
While there's no direct rename operation, we can achieve this through a resource move pattern. Here's the complete PowerShell workflow:
# First, stop and deallocate the VM (required for the operation)
Stop-AzVM -ResourceGroupName "YourResourceGroup" -Name "OldVMName" -Force
# Get the VM configuration
$vm = Get-AzVM -ResourceGroupName "YourResourceGroup" -Name "OldVMName"
# Create a new VM configuration with the desired name
$newVM = New-AzVMConfig -VMName "NewVMName" -VMSize $vm.HardwareProfile.VmSize
# Copy all existing properties
$newVM.OSProfile = $vm.OSProfile
$newVM.StorageProfile = $vm.StorageProfile
$newVM.NetworkProfile = $vm.NetworkProfile
$newVM.Location = $vm.Location
# Create the new VM (this will effectively rename it)
New-AzVM -ResourceGroupName "YourResourceGroup" -Location $vm.Location -VM $newVM
# Verify the new VM exists
Get-AzVM -ResourceGroupName "YourResourceGroup" -Name "NewVMName"
# Once confirmed working, remove the old resource
Remove-AzVM -ResourceGroupName "YourResourceGroup" -Name "OldVMName"
1. IP Addresses: Public IPs won't carry over. You'll need to associate a new one or reconfigure existing ones.
2. Disks: Managed disks retain their original names but will be associated with the new VM.
3. Tags: Any existing tags will need to be manually reapplied to the new resource.
For simpler cases, you can recreate the VM from the original disks:
# Capture the original VM's OS disk ID
$diskId = (Get-AzVM -ResourceGroupName "YourResourceGroup" -Name "OldVMName").StorageProfile.OsDisk.ManagedDisk.Id
# Create new VM configuration
$newVM = New-AzVMConfig -VMName "NewVMName" -VMSize "Standard_DS2_v2"
$newVM = Set-AzVMOSDisk -VM $newVM -ManagedDiskId $diskId -CreateOption Attach
# Complete the VM creation
New-AzVM -ResourceGroupName "YourResourceGroup" -Location "EastUS" -VM $newVM
For production environments, follow this sequence:
- Document all current VM configurations
- Take backups/snapshots of all attached disks
- Perform the rename operation during a maintenance window
- Update any automation scripts or deployment templates referencing the old name