$diskName = 'yourDiskName'
# resource group that contains the managed disk
$rgName = 'yourResourceGroupName'
# Choose between StandardSSD_ZRS or Premium_ZRS based on your scenario
$storageType = 'Premium_ZRS'
# Premium capable size
$size = 'Standard_DS2_v2'
$disk = Get-AzDisk -DiskName $diskName -ResourceGroupName $rgName
# Get parent VM resource
$vmResource = Get-AzResource -ResourceId $disk.ManagedBy
# Stop and deallocate the VM before changing the storage type
Stop-AzVM -ResourceGroupName $vmResource.ResourceGroupName -Name $vmResource.Name -Force
$vm = Get-AzVM -ResourceGroupName $vmResource.ResourceGroupName -Name $vmResource.Name
# Change the VM size to a size that supports Premium storage
# Skip this step if converting storage from Premium to Standard
$vm.HardwareProfile.VmSize = $size
Update-AzVM -VM $vm -ResourceGroupName $rgName
# Update the storage type
$disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
$disk | Update-AzDisk
Start-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name
#resource group that contains the managed disk
$rgName='yourResourceGroup'
#Name of your managed disk
diskName='yourManagedDiskName'
#Premium capable size
#Required only if converting from Standard to Premium
size='Standard_DS2_v2'
#Choose between StandardSSD_ZRS or Premium_ZRS based on your scenario
sku='Premium_ZRS'
#Get the parent VM Id
vmId=$(az disk show --name $diskName --resource-group $rgName --query managedBy --output tsv)
#Deallocate the VM before changing the size of the VM
az vm deallocate --ids $vmId
#Change the VM size to a size that supports Premium storage
#Skip this step if converting storage from Premium to Standard
az vm resize --ids $vmId --size $size
# Update the SKU
az disk update --sku $sku --name $diskName --resource-group $rgName
az vm start --ids $vmId
# Create a new ZRS Managed Disks using the snapshot Id and the SKU supported
storageType=Premium_ZRS
location=westus2
az disk create --resource-group $resourceGroupName --name $diskName --sku $storageType --size-gb $diskSize --source $snapshotId
步驟 3:使用新磁碟建立新的 VM
現在,您已將資料移轉至 ZRS 受控磁碟或區域性受控磁碟,接下來請將這些新磁碟設定為 OS 和資料磁碟,以建立新的 VM:
az vm create -g MyResourceGroup -n MyVm --attach-os-disk newZonalOSDiskCopy --attach-data-disks newZonalDataDiskCopy --os-type linux