Use PowerShell to resize a 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 in the region where the VM is hosted.
Get-AzVMSize -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-AzVM -ResourceGroupName $resourceGroup -VMName $vmName
$vm.HardwareProfile.VmSize = "<newVMsize>"
Update-AzVM -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 <newVMsize> with the size you want.
Stop-AzVM -ResourceGroupName $resourceGroup -Name $vmName -Force
$vm = Get-AzVM -ResourceGroupName $resourceGroup -VMName $vmName
$vm.HardwareProfile.VmSize = "<newVMSize>"
Update-AzVM -VM $vm -ResourceGroupName $resourceGroup
Start-AzVM -ResourceGroupName $resourceGroup -Name $vmName
Warning
Deallocating the VM also releases any dynamic IP addresses assigned to the VM. The OS and data disks are not affected.
If you are resizing a production VM, consider using Azure Capacity Reservations to reserve Compute capacity in the region.
Use PowerShell to resize a 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-AzVMSize `
-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-AzVM `
-ResourceGroupName $resourceGroup `
-VMName $vmName
$vm.HardwareProfile.VmSize = "<newVmSize>"
Update-AzVM `
-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.
$availabilitySetName = "<availabilitySetName>"
$as = Get-AzAvailabilitySet `
-ResourceGroupName $resourceGroup `
-Name $availabilitySetName
$virtualMachines = $as.VirtualMachinesReferences | Get-AzResource | Get-AzVM
$virtualMachines | Stop-AzVM -Force -NoWait
Resize and restart the VMs in the availability set.
$availabilitySetName = "<availabilitySetName>"
$newSize = "<newVmSize>"
$as = Get-AzAvailabilitySet -ResourceGroupName $resourceGroup -Name $availabilitySetName
$virtualMachines = $as.VirtualMachinesReferences | Get-AzResource | Get-AzVM
$virtualMachines | Foreach-Object { $_.HardwareProfile.VmSize = $newSize }
$virtualMachines | Update-AzVM
$virtualMachines | Start-AzVM