Resize a Windows VM

This article shows you how to move a VM to a different VM size using Azure Powershell.

After you create a virtual machine (VM), you can scale the VM up or down by changing the VM size. In some cases, you must deallocate the VM first. This can happen if the new size is not available on the hardware cluster that is currently hosting the VM.

If your VM uses Premium Storage, make sure that you choose an s version of the size to get Premium Storage support. For example, choose Standard_E4s_v3 instead of Standard_E4_v3.

Resize a Windows VM not in an availability set

Set some variables. Replace the values with your own information.

$resourceGroup = "myResourceGroup"
$vmName = "myVM"

List the VM sizes that are available on the hardware cluster where the VM is hosted.

Get-AzureRmVMSize -ResourceGroupName $resourceGroup -VMName $vmName 

If the size you want is listed, run the following commands to resize the VM. If the desired size is not listed, go on to step 3.

$vm = Get-AzureRmVM -ResourceGroupName $resourceGroup -VMName $vmName
$vm.HardwareProfile.VmSize = "<newVMsize>"
Update-AzureRmVM -VM $vm -ResourceGroupName $resourceGroup

If the size you want is not listed, run the following commands to deallocate the VM, resize it, and restart the VM. Replace with the size you want.

Stop-AzureRmVM -ResourceGroupName $resourceGroup -Name $vmName -Force
$vm = Get-AzureRmVM -ResourceGroupName $resourceGroup -VMName $vmName
$vm.HardwareProfile.VmSize = "<newVMSize>"
Update-AzureRmVM -VM $vm -ResourceGroupName $resourceGroup
Start-AzureRmVM -ResourceGroupName $resourceGroup -Name $vmName

Warning

Deallocating the VM releases any dynamic IP addresses assigned to the VM. The OS and data disks are not affected.

Resize a Windows VM in an availability set

If the new size for a VM in an availability set is not available on the hardware cluster currently hosting the VM, then all VMs in the availability set will need to be deallocated to resize the VM. You also might need to update the size of other VMs in the availability set after one VM has been resized. To resize a VM in an availability set, perform the following steps.

$resourceGroup = "myResourceGroup"
$vmName = "myVM"

List the VM sizes that are available on the hardware cluster where the VM is hosted.

Get-AzureRmVMSize -ResourceGroupName $resourceGroup -VMName $vmName 

If the desired size is listed, run the following commands to resize the VM. If it is not listed, go to the next section.

$vm = Get-AzureRmVM -ResourceGroupName $resourceGroup -VMName $vmName 
$vm.HardwareProfile.VmSize = "<newVmSize>"
Update-AzureRmVM -VM $vm -ResourceGroupName $resourceGroup

If the size you want is not listed, continue with the following steps to deallocate all VMs in the availability set, resize VMs, and restart them.

Stop all VMs in the availability set.

$as = Get-AzureRmAvailabilitySet -ResourceGroupName $resourceGroup
$vmIds = $as.VirtualMachinesReferences
foreach ($vmId in $vmIDs){
    $string = $vmID.Id.Split("/")
    $vmName = $string[8]
    Stop-AzureRmVM -ResourceGroupName $resourceGroup -Name $vmName -Force
    } 

Resize and restart the VMs in the availability set.

$newSize = "<newVmSize>"
$as = Get-AzureRmAvailabilitySet -ResourceGroupName $resourceGroup
$vmIds = $as.VirtualMachinesReferences
  foreach ($vmId in $vmIDs){
    $string = $vmID.Id.Split("/")
    $vmName = $string[8]
    $vm = Get-AzureRmVM -ResourceGroupName $resourceGroup -Name $vmName
    $vm.HardwareProfile.VmSize = $newSize
    Update-AzureRmVM -ResourceGroupName $resourceGroup -VM $vm
    Start-AzureRmVM -ResourceGroupName $resourceGroup -Name $vmName
    }

Next steps

For additional scalability, run multiple VM instances and scale out. For more information, see Automatically scale Windows machines in a Virtual Machine Scale Set.