1

I am trying to resize an Azure VM using command line. The VM size is listed in the list of sizes that this VM can be resized to. But when I try to resize this VM I am unable to do because of this error

Unable to resize the VM 'XYZ' because the requested size Standard_F4s is not available in the current hardware cluster.

Is there a way we can get the information beforehand to which all sizes this VM can be resized to successfully?

user1142317
  • 533
  • 1
  • 8
  • 20

3 Answers3

4

You can use Get-AzureRmVmSize to check VM size. The sample below does not only check hardware cluster but also disk, region availability to make sure you can resize your VM.

$rg = "azuredev-rg"
$vmName = "A0VM"
Get-AzureRmVMSize -ResourceGroupName $rg -VMName $vmName

Note that the output is dependent on the VM status running. You can change your existing VM size when it is running. However, not all available sizes are listed if that VM is running. It means some designated sizes require stopping VM to be deallocated first (due to different hardware cluster)

For defensive programming, below sample would be a consideration to check VM status before performing resizing

$vm = (Get-AzureRmVM -ResourceGroupName $rg -Name $vmName -Status).Statuses
$vm.DisplayStatus

The output shows you

Provisioning succeeded
VM running

Below is the sample PowerShell script to check VM status then perform resizing

$rg = "azuredev-rg"
$vmName = "A0VM"
$newSize = "Standard_B1s"

$vm = Get-AzureRmVM -ResourceGroupName $rg -Name $vmName
$vmS = Get-AzureRmVMSize -ResourceGroupName $rg -VMName $vmName

if ($vmS.Name -contains $newSize) 
{
    Write-Output "This size is supported"
    $vm.HardwareProfile.VmSize = $newSize
    Update-AzureRmVM -VM $vm -ResourceGroupName $rg
    Write-Output "The VM size is being updated"
}

else
{
    while($vmStatus.DisplayStatus -contains "VM running")
    {
        $vmStatus = (Get-AzureRmVM -ResourceGroupName $rg -Name $vmName -Status).Statuses
        Write-Output $vmStatus
        Write-Output "VM is being stopped"
        Start-Sleep -Seconds 3
    }
    Stop-AzureRmVM -Name $vmName -ResourceGroupName $rg -Force
    $vm.HardwareProfile.VmSize = $newSize
    Update-AzureRmVM -VM $vm -ResourceGroupName $rg
}
EagleDev
  • 1,754
  • 2
  • 11
  • 31
  • Thank you. Exactly what I needed !!! The corresponding REST API is https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines//vmSizes?api-version=2017-12-01 – user1142317 Mar 05 '18 at 22:05
  • how do you stop VM in the while loop? – toto' Jul 26 '18 at 12:15
0

Agree with Thuan Ng.

If your VM(s) are deployed using the Resource Manager (ARM) deployment model and you need to change to a size which requires different hardware then you can resize VMs by first stopping your VM, selecting a new VM size and then restarting the VM.

Is there a way we can get the information beforehand to which all sizes this VM can be resized to successfully?

Do you mean you want to get which all sizes in current hardware are available?

Based on my knowledge, it is not possible.

The resize operation is a simple reboot operation, maybe we can stop it first and resize it, then restarting the VM.

Jason Ye
  • 13,710
  • 2
  • 16
  • 25
0

If by command line you mean azure-cli, you can always use:

az vm list-vm-resize-options -g test-resourcegroup -n test-vm -o table

As a result you'll see vm sizes you can use in az vm resize without the need for deallocate. If you'd like to check what's available in the location of your interest you can use something like: az vm list-sizes -l westeurope -o table You can use any size listed in the output of the command above when you az vm deallocate this VM. If you're interested in more detail you can check this article.