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
}