Skip to content

Commit 6fbea2f

Browse files
Merge branch 'main' of https://github.com/MicrosoftDocs/azure-docs-pr into aca/quotas
2 parents 30a4b64 + 90b4bbb commit 6fbea2f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

articles/virtual-machines/windows/change-availability-set.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ This article was last tested on 2/12/2019 using the [Azure Cloud Shell](https://
3131
## Change the availability set
3232

3333
The following script provides an example of gathering the required information, deleting the original VM and then recreating it in a new availability set.
34+
The below scenario also covers an optional portion where we create a snapshot of the VM's OS disk in order to create disk from the snapshot to have a backup because when the VM gets deleted, the OS disk will also be deleted along with it.
3435

3536
```powershell
3637
# Set variables
3738
$resourceGroup = "myResourceGroup"
3839
$vmName = "myVM"
3940
$newAvailSetName = "myAvailabilitySet"
41+
$snapshotName = "MySnapShot"
4042
4143
# Get the details of the VM to be moved to the Availability Set
4244
$originalVM = Get-AzVM `
@@ -57,10 +59,30 @@ The following script provides an example of gathering the required information,
5759
-PlatformUpdateDomainCount 2 `
5860
-Sku Aligned
5961
}
60-
62+
63+
# Get Current VM OS Disk metadata
64+
$osDiskid = $originalVM.StorageProfile.OsDisk.ManagedDisk.Id
65+
$osDiskName = $originalVM.StorageProfile.OsDisk.Name
66+
67+
# Create Disk Snapshot (optional)
68+
$snapshot = New-AzSnapshotConfig -SourceUri $osDiskid `
69+
-Location $originalVM.Location `
70+
-CreateOption copy
71+
72+
$newsnap = New-AzSnapshot `
73+
-Snapshot $snapshot `
74+
-SnapshotName $snapshotName `
75+
-ResourceGroupName $resourceGroup
76+
6177
# Remove the original VM
6278
Remove-AzVM -ResourceGroupName $resourceGroup -Name $vmName
6379
80+
# Create disk out of snapshot (optional)
81+
$osDisk = New-AzDisk -DiskName $osDiskName -Disk `
82+
(New-AzDiskConfig -Location $originalVM.Location -CreateOption Copy `
83+
-SourceResourceId $newsnap.Id) `
84+
-ResourceGroupName $resourceGroup
85+
6486
# Create the basic configuration for the replacement VM.
6587
$newVM = New-AzVMConfig `
6688
-VMName $originalVM.Name `
@@ -107,6 +129,9 @@ The following script provides an example of gathering the required information,
107129
-Location $originalVM.Location `
108130
-VM $newVM `
109131
-DisableBginfoExtension
132+
133+
# Delete Snapshot (optional)
134+
Remove-AzSnapshot -ResourceGroupName $resourceGroup -SnapshotName $snapshotName -Force
110135
```
111136

112137
## Next steps

0 commit comments

Comments
 (0)