Resize a Windows VM in Azure

10/19/2016 2 min to read Contributors

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.
    Copy
    PowerShell
     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.
    Copy
    PowerShell
     $vm = Get-AzureRmVM -ResourceGroupName <resourceGroupName> -VMName <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.
    Copy
    PowerShell
     $rgname = "<resourceGroupName>"
     $vmname = "<vmName>"
     Stop-AzureRmVM -ResourceGroupName $rgname -VMName $vmname -Force
     $vm = Get-AzureRmVM -ResourceGroupName $rgname -VMName $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.
    Copy
    PowerShell
     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.
    Copy
    PowerShell
     $vm = Get-AzureRmVM -ResourceGroupName <resourceGroupName> -VMName <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.
    Copy
    PowerShell
    $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.
    Copy
    PowerShell
    $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
    }

     

Please find the reference article – https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-resize-vm

Posted by Sheikvara

+919840688822, +919003270444

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s