Resizing a virtual machine (VM) in Azure is a simple feat if you know your PowerShell. Luckily, in this article, I'll be showing you how to create a PowerShell script to resize your Azure VMs that are either in an availability set or not.

First, to manage anything in Azure with PowerShell, you'll need to get your hands on the Az PowerShell module. To do this, run Install-Module Az. This will download the module and make it available in your PowerShell session. I'm also going to assume you have an Azure VM either in or not in an availability set. With that out of the way, let's look at how to resize Azure VMs with PowerShell!

Listing available sizes ^

Before we can resize a VM, we must first know which sizes are available. To do this, we can run the Get-AzVmSize command against the VM in question. I'll be working with a VM called CLIENT in this example. CLIENT is in the LAB resource group.

Listing VM sizes

Listing VM sizes

Resizing a VM not in an availability set ^

You can see we've got a lot of sizes to choose from. If you see a size you'd like, first create an instance of the VM using Get-AzVm.

Next, change the VmSize property on that VM instance to the new size. In my case, I'll randomly pick the Standard_D3 size.

Once I've saved the VM instance variable with the new size in my PowerShell session, it's then time to send that change up to Azure by running Update-AzVM and providing the VM instance and the resource group name the VM is in.

This may take a bit to run as it does not work in the background. If you wanted to run this command in the background, you have the option of using the AsJob parameter.

Once this is complete, you should see an output like the one below:

At this point, we can now check the VM size again by inspecting the VmSize property on the HardwareProfile object that's part of the VM instance object.

Resizing a VM in an availability set ^

Finally, we can also resize VMs in an availability set using a similar approach. If a VM is in an availability set and the size you need is not available when running Get-AzVmSize, you can still change the size if you shut down all VMs in the availability set, update the sizes of all VMs, and then start up the VMs again.

We'll first find all of the VMs in the availability set and stop them all.

After stopping all the VMs, we can now use the same method we used earlier for updating the VMs—but this time we update all the VMs in the availability set.

 

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!

2+
avatar
Share
2 Comments
  1. In the current state, Microsoft Resize solution is not completely Elastic in cloud computing sense.
    Azure Datacentre is organized into multiple Stamp units. Every stamp unit has the hardware of similar configuration and supports a certain list of virtual machine sizes only. Resize or vertical scaling operation is scoped by this list of supported vm sizes in current stamp unit vm is hosted in.
    Even the Redeploy machine provisions the vm to one of the node within the stamp.
    As a workaround for this limitation, we have to create a new vm from the disks from the previous VMs requiring downtime for migration. 

    0

  2. Ali Razeghi 2 months ago

    Thank you!

    0

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2020

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account