Resize a Windows VM

This article shows you how to resize a Windows VM, created in the Resource Manager deployment model 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.

Resize a Windows VM not in an availability set

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

    Get-AzureRmVMSize -ResourceGroupName <resourceGroupName> -VMName <vmName> 
    
  2. If the desired size 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 <resourceGroupName> -Name <vmName>
    $vm.HardwareProfile.VmSize = "<newVMsize>"
    Update-AzureRmVM -VM $vm -ResourceGroupName <resourceGroupName>
    
  3. If the desired size is not listed, run the following commands to deallocate the VM, resize it, and restart the VM.

    $rgname = "<resourceGroupName>"
    $vmname = "<vmName>"
    Stop-AzureRmVM -ResourceGroupName $rgname -Name $vmname -Force
    $vm = Get-AzureRmVM -ResourceGroupName $rgname -Name $vmname
    $vm.HardwareProfile.VmSize = "<newVMSize>"
    Update-AzureRmVM -VM $vm -ResourceGroupName $rgname
    Start-AzureRmVM -ResourceGroupName $rgname -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.

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

    Get-AzureRmVMSize -ResourceGroupName <resourceGroupName> -VMName <vmName>
    
  2. If the desired size is listed, run the following commands to resize the VM. If it is not listed, go to step 3.

    $vm = Get-AzureRmVM -ResourceGroupName <resourceGroupName> -Name <vmName>
    $vm.HardwareProfile.VmSize = "<newVmSize>"
    Update-AzureRmVM -VM $vm -ResourceGroupName <resourceGroupName>
    
  3. If the desired size is not listed, continue with the following steps to deallocate all VMs in the availability set, resize VMs, and restart them.
  4. Stop all VMs in the availability set.

    $rg = "<resourceGroupName>"
    $as = Get-AzureRmAvailabilitySet -ResourceGroupName $rg
    $vmIds = $as.VirtualMachinesReferences
    foreach ($vmId in $vmIDs){
      $string = $vmID.Id.Split("/")
      $vmName = $string[8]
      Stop-AzureRmVM -ResourceGroupName $rg -Name $vmName -Force
    } 
    
  5. Resize and restart the VMs in the availability set.

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

Next steps