How to Stop a VM in Azure: Simple Commands and Steps
To stop a VM in Azure, use the
az vm stop command in Azure CLI or the Stop-AzVM cmdlet in PowerShell. You can also stop the VM from the Azure Portal by selecting the VM and clicking the Stop button.Syntax
Here are the main ways to stop a VM in Azure:
- Azure CLI:
az vm stop --resource-group <group-name> --name <vm-name> - PowerShell:
Stop-AzVM -ResourceGroupName <group-name> -Name <vm-name> - Azure Portal: Navigate to your VM and click the
Stopbutton.
Replace <group-name> and <vm-name> with your actual resource group and VM names.
bash
az vm stop --resource-group MyResourceGroup --name MyVm Stop-AzVM -ResourceGroupName MyResourceGroup -Name MyVm
Example
This example shows how to stop a VM named MyVm in the resource group MyResourceGroup using Azure CLI.
bash
az vm stop --resource-group MyResourceGroup --name MyVm
Output
Operation completed successfully.
Common Pitfalls
Common mistakes when stopping a VM include:
- Using the wrong resource group or VM name, causing the command to fail.
- Confusing
az vm stopwithaz vm deallocate.stopstops the VM but still reserves resources, whiledeallocatereleases resources and stops billing. - Not having the right permissions to stop the VM.
bash
Wrong command (does not deallocate VM): az vm stop --resource-group MyResourceGroup --name MyVm Correct command to deallocate VM: az vm deallocate --resource-group MyResourceGroup --name MyVm
Quick Reference
| Action | Command | Description |
|---|---|---|
| Stop VM | az vm stop --resource-group | Stops the VM but keeps resources allocated |
| Deallocate VM | az vm deallocate --resource-group | Stops VM and releases resources, stopping billing |
| PowerShell Stop | Stop-AzVM -ResourceGroupName | Stops the VM using PowerShell |
| Azure Portal | Click Stop button on VM page | Stops the VM via Azure Portal UI |
Key Takeaways
Use
az vm stop to stop a VM while keeping resources allocated.Use
az vm deallocate to stop and release resources to save costs.Always specify the correct resource group and VM name.
Stopping a VM requires proper permissions in Azure.
You can also stop VMs easily from the Azure Portal UI.