0
0
AzureHow-ToBeginner · 3 min read

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 Stop button.

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 stop with az vm deallocate. stop stops the VM but still reserves resources, while deallocate releases 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

ActionCommandDescription
Stop VMaz vm stop --resource-group --name Stops the VM but keeps resources allocated
Deallocate VMaz vm deallocate --resource-group --name Stops VM and releases resources, stopping billing
PowerShell StopStop-AzVM -ResourceGroupName -Name Stops the VM using PowerShell
Azure PortalClick Stop button on VM pageStops 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.