October 3, 2017

Microsoft Azure - Add existing VM to Availability Set

Currently it is not possible to add an existing Azure Virtual Machine to Availability Set. VM needs to be re-created because Availability Set setting can be specified only during deployment stage. Below is a script which automates this process. It is assumed that VM is managed by Resource Manager, OS disk is managed, no data disks are attached and VM has only one nic. The script gathers current information about Virtual Machine and saves it to txt file (Set-AzureVMAS.txt). It includes such fields as VM Name, Extensions, VM Size and NIC, Operating System and Disk information. Then script re-creates Virtual Machine and sets needed Availability Set. $VMName, $ResourceGroup and $AvailabilitySet variables in a header of the script need to be specified. Script also works with VM’s which are already in another AS so can be used to move VM's between Availability Sets.

No comments:

Post a Comment