Lab 028: Change Azure Virtual Machine Size Using CLI
Requirements
You are tasked with below:
-
Change the VM size from Standard_B1s to Standard_B2s for the VM named xfusion-vm through Azure CLI only.
-
Make sure the VM xfusion-vm is in running state after the change.
Note
This page preserves the original task statement and uses one primary Azure CLI workflow to resize and restart the VM.
Prerequisites
- Azure CLI is installed and authenticated.
- Target VM
xfusion-vmalready exists. - You have permissions to deallocate, resize, and start the VM.
Steps
For the Azure credentials, enter showcreds command. For further details, check out the Project Nautilus documentation.
# Declare variables
RG=$(az group list --query "[?contains(name, 'kml')].name" --output tsv)
VM_NAME=xfusion-vm
NEW_SIZE=Standard_B2s
# Stop the VM
az vm deallocate --resource-group $RG --name $VM_NAME
# Resize the VM
az vm resize --resource-group $RG --name $VM_NAME --size $NEW_SIZE
# Start the VM
az vm start --resource-group $RG --name $VM_NAME
# Ensure the VM is running
az vm get-instance-view --resource-group $RG --name $VM_NAME --query instanceView.statuses[1] --output table
Verification
- Confirm VM size changed to
Standard_B2s. - Confirm VM is running after resize.
az vm show --resource-group "$RG" --name "$VM_NAME" --query "{Name:name,Size:hardwareProfile.vmSize}" --output table
az vm get-instance-view --resource-group "$RG" --name "$VM_NAME" --query "instanceView.statuses[].displayStatus" --output table