In this section, you are going to resize the myVM virtual machine that you created earlier. However, before attempting to do so, you will need to retrieve a list of VM sizes available in the EastUS region, which is where the myVM virtual machine resides.
To complete this task, run the following command from PowerShell:
Get-AzureRmVMSize -Location "EastUS"
The preceding command should return quite a few sizes. Confirm that Standard DS2_V2 is available. If it's not, find another size that is available.
After confirming that Standard DS2_V2 (or your chosen size) is available, you can use PowerShell to resize the myVM virtual machine:
After confirming that Standard DS2_V2 is available in the EastUS region, you also need to make sure that it's available on the current cluster where the myVM virtual machine resides. To do so, use the same Get-AzureRmVMSize command as before—just with a few different switches.
To confirm that the Standard DS2_V2 size (or your chosen size) is available on the cluster where myVM resides, run the following command:
Get-AzureRmVMSize -ResourceGroupName "VMLab" -VMName "myVM"
By specifying the -VMName and -ResourceGroupName switches in the preceding command, you can confirm that the Standard DS2_V2 size is available on the same cluster as the VM. If so, the virtual machine can be resized from a powered-on state (without the need to deallocate it). However, it will still require a reboot during the operation:
If the Standard DS2_V2 size is not available on the VM's current cluster, the virtual machine needs to first be deallocated before the resize operation can occur. In such a case, any data on the temp disk is removed and the public IP address will change (unless a static IP address is being used).
To resize the virtual machine (myVM), you need to run a few different PowerShell commands.
The first command essentially loads the configuration profile of the VM into a variable called $vm. The second command will modify the -VMSize attribute stored in that variable to reflect the new VM size. The third command, called Update-AzureRmVM, will take the updated configuration that is stored in the $vm variable and write it to the VM.
To begin the resize process of the myVM virtual machine, run the following command from a PowerShell session that's connected to your Azure tenant:
$vm = Get-AzureRmVM -ResourceGroupName "VMLab" -VMName "myVM"
The preceding command retrieves the current VM information and stores it in the $vm variable.
To modify the size attribute for the VM, run the following command:
$vm.HardwareProfile.VmSize = "Standard_DS2_V2"
The previous command changes the size attribute of the myVM virtual machine that's stored in the variable to Standard DS2_V2.
Once the new size has been specified using the preceding command, run the following command to update the VM:
Update-AzureRmVM -VM $vm -ResourceGroupName "VMLab"
After executing the preceding Update-AzureRmVM command, the myVM virtual machine is updated and then automatically restarted:
The process takes a few minutes to complete, but when it completes, the myVM virtual machine is resized to reflect the new size.