Skip to content

Commit f3fefbd

Browse files
authored
Fix Update-AzDisk to not be destructive
The current method of updating the disk: $diskUpdateConfig = New-AzDiskUpdateConfig -AccountType $storageType -DiskSizeGB $disk.DiskSizeGB Update-AzDisk -DiskUpdate $diskUpdateConfig -ResourceGroupName $rgName ` -DiskName $disk.Name Will cause loss of properties on the disk (ie. tags). Update-AzDisk does not get all of the original properties of the current disk, and it is a PUT operation, which means it is just doing a PUT of whatever is specified in the New-AzDiskUpdateConfig result, which means anything not specified in the request will be lost (ie. tags are removed). This method will just update the properties that you are trying to change and preserve everything else: $disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType) $disk | Update-AzDisk
1 parent c052676 commit f3fefbd

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

articles/virtual-machines/windows/convert-disk-storage.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ foreach ($disk in $vmDisks)
5858
{
5959
if ($disk.ManagedBy -eq $vm.Id)
6060
{
61-
$diskUpdateConfig = New-AzDiskUpdateConfig –AccountType $storageType
62-
Update-AzDisk -DiskUpdate $diskUpdateConfig -ResourceGroupName $rgName `
63-
-DiskName $disk.Name
61+
$disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
62+
$disk | Update-AzDisk
6463
}
6564
}
6665
@@ -97,9 +96,8 @@ $vm.HardwareProfile.VmSize = $size
9796
Update-AzVM -VM $vm -ResourceGroupName $rgName
9897
9998
# Update the storage type
100-
$diskUpdateConfig = New-AzDiskUpdateConfig -AccountType $storageType -DiskSizeGB $disk.DiskSizeGB
101-
Update-AzDisk -DiskUpdate $diskUpdateConfig -ResourceGroupName $rgName `
102-
-DiskName $disk.Name
99+
$disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
100+
$disk | Update-AzDisk
103101
104102
Start-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name
105103
```
@@ -142,9 +140,8 @@ Stop-AzVM -ResourceGroupName $vmResource.ResourceGroupName -Name $vmResource.Nam
142140
$vm = Get-AzVM -ResourceGroupName $vmResource.ResourceGroupName -Name $vmResource.Name
143141
144142
# Update the storage type
145-
$diskUpdateConfig = New-AzDiskUpdateConfig -AccountType $storageType -DiskSizeGB $disk.DiskSizeGB
146-
Update-AzDisk -DiskUpdate $diskUpdateConfig -ResourceGroupName $rgName `
147-
-DiskName $disk.Name
143+
$disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
144+
$disk | Update-AzDisk
148145
149146
Start-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name
150147
```

0 commit comments

Comments
 (0)