One big limitation you may encounter when dealing with Microsoft Azure is the ability to change an Azure Virtual Machines Availability Set configuration. This includes adding an existing VM to an Availability Set, move a VM from one Availability Set to another, and removing a VM from an Availability Set. In this article, I will go through the process of doing this using a PowerShell script created by Paulo Marques.
In fact you can vote for this feature to be added via this link.
You will need to have the latest PowerShell module installed.
Now we can import the PowerShell module from the PowerShell gallery using the following command.
Now you have to connect up to your Azure subscription. Use the following command to connect up.
Now its time to select the Azure subscription you want to work with. This can be done using the following command.
|Select-AzureRmSubscription -SubscriptionID "your subscription ID"|
To get a list of available functions type:
|Get-Command -Module AzureRm.AvailabilitySetManagement|
If you do not have an Availability Set already create one now. You can create one using the following PowerShell. Just change the settings to match your set up.
|New-AzureRmAvailabilitySet -Location "East US 2" -Name "myAvailabilitySet" -ResourceGroupName "PixelRobots" -Sku aligned -PlatformFaultDomainCount 2 -PlatformUpdateDomainCount 2|
You are now ready to move your VM to an Availability Set.
Add A Virtual Machine To An Availability Set
You can use the following code to do that. Please note that your VM will be unavailable during the move.
|Add-AzureRmAvSetVmToAvailabilitySet -ResourceGroupName "PixelRobots" -VMName "VM1" -OsType windows -AvailabilitySet "myAvailabilitySet"|
|Get-AzureRmAvailabilitySet -ResourceGroupName "PixelRobots" -Name "myAvailabilitySet"|
Remove A Virtual Machine From An Availability Set
To remove a virtual machine from an availability set use the following command. Please note that your VM will be unavailable during the move.
|Remove-AzureRmAvSetVmFromAvailabilitySet -ResourceGroupName "PixelRobots" -VMName vm1 -OsType windows|
That’s it. You can now easily move and remove an existing Azure Virtual Machines into an Availability Set. I hope you found this article helpful. If you have any questions please drop a message below.
I’m Richard Hooper aka Pixel Robots. I started this blog in 2016 for a couple reasons. The first reason was basically just a place for me to store my step by step guides, troubleshooting guides and just plain ideas about being a sysadmin. The second reason was to share what I have learned and found out with other people like me. Hopefully, you can find something useful on the site.