PowerShell: Resizing Azure Virtual Machines


Did you know that you can scale virtual machines in Microsoft Azure? If you’ve been working with the cloud, you’ve most likely heard about that capability before, but did you know that you can automate this function using PowerShell? It’s true! You can streamline many different operations in Microsoft Azure, using the Azure PowerShell module.

One of the common cloud scenarios is building applications that can scale horizontally, meaning that you have a dynamic number of instances performing work on the same application. However, you can also scale Azure virtual machines vertically, meaning that you can increase the hardware specifications of your VMs. These concepts are discussed in the MSDN article “Autoscaling Guidance.” In Microsoft Azure, the virtual machine size is known as the “role size.” Using the Azure PowerShell module, you can easily increase or decrease the number of CPU cores that are allocated to your VMs, change the amount of memory, and the maximum number of data disks that attached to the VM.

In fact, there is a great MSDN reference article that points out all of the unique properties of each virtual machine role size.

Most large enterprises would use completely silent automation to resize virtual machines, based off of some metric or time period. If you’re a developer, tester, or IT pro, you might just need a simple user interface to resize your VMs on-demand. To that end, I have put together a simple PowerShell function that will prompt you to select an Azure virtual machine, and the target role size, without having to type out the lengthy commands every time! Without this script, you would have to run Get-AzureVM, followed by Set-AzureRoleSize, followed by Update-AzureVM, which can result in a lot of typing. If you want to speed up this process, and type less, you can use my Resize-AzureVM PowerShell function below!


Select Azure VM

Select Azure VM

The directions to “install” the Resize-AzureVM command are pretty straightforward. All you need to do is add the function definition to your PowerShell “profile” script, to ensure that it is always available when you launch a PowerShell instance.

  1. Make sure the Microsoft Azure PowerShell module is installed.
  2. Copy / paste the function into your local PowerShell profile
  3. Call the Add-AzureAccount command to authenticate to Microsoft Azure
  4. (optional) Call the Select-AzureSubscription command to select the appropriate Azure subscription, if you have more than one
  5. Call the Resize-AzureVM command to resize your Azure virtual machine(s)!

This function is just one of many tools that can be built around the Azure PowerShell module, to simplify cloud operations. By leveraging PowerShell’s Out-GridView command, we can easily create a user interface to select options that drive our PowerShell scripts! For another example of Azure PowerShell tooling, check out my azrdp function, which I published just recently!

Feel free to follow me on Twitter for more status updates surrounding the Microsoft enterprise platform!

One Comment:

  1. Pingback: Dew Drop – April 7, 2015 (#1988) | Morning Dew

Comments are closed