The fastest way to gain control over your environment is through the Command Line Interface (CLI). In this article, I’m going to show you exactly how to Start and Stop Azure VMs using the Azure CLI like a pro.
Table of Contents
- Start/Stop VM Using Azure CLI
- Best Practices
- Video Tutorial
- Summary
Start/Stop VM Using Azure CLI
Understanding the “Stop” vs. “Deallocate” Trap
In Azure, “Stopped” does not always mean “Free.”
| State | Action Trigger | Billing Status | What Happens? |
| Stopped | Shutdown via Guest OS | Incurring Charges | The OS is off, but Azure still reserves the hardware and IP for you. |
| Stopped (Deallocated) | Stopped via CLI/Portal | No Compute Charges | The hardware is released. You only pay for storage (disks). |
Pro Tip: Always stop your VMs via the CLI or Portal to ensure they reach the Deallocated state. If you just remote in and click “Shut Down” inside Windows or Linux, you’re still paying for that compute!
Step 1: Setting Up Your Environment
To follow along, you’ll need the Azure CLI installed on your machine.
- Check your version: Open your terminal and run
az --version. - Login: You must authenticate your session. Run
az login. This will open a browser window; once you sign in with your corporate or personal account, you’re ready. - Set your Subscription: If you have multiple subscriptions (e.g., Pay-As-You-Go and an Enterprise Agreement), make sure you are in the right context:
az account set --subscription "Your-Subscription-Name"
Step 2: Starting an Azure VM via CLI
Starting a VM is the most straightforward operation. This is particularly useful for “warming up” environments before a team starts their workday.
Basic Start Command
To start a specific VM, you need two pieces of information: the Resource Group and the VM Name.
Code snippet
az vm start --resource-group demo --name AzureLessonsLinuxVMAfter executing the command above, I received the expected output, as shown in the screenshot below.

Starting Multiple VMs
If you want to start all VMs in a specific group, you don’t have to run the command 20 times. You can use a query to grab the IDs and pipe them:
- Logic: List all VMs in the group, get their IDs, and start them.
- Benefit: Zero manual clicking.
Step 3: Stopping and Deallocating VMs
As I mentioned earlier, our goal is usually to Stop and Deallocate to save money. The az vm stop command in the CLI actually triggers a deallocation by default unless you specify otherwise.
The Standard Stop Command
This is the command I use for my daily “End of Day” scripts for the dev team:
Code snippet
az vm stop --resource-group demo --name AzureLessonsLinuxVMAfter executing the command above, I received the expected output, as shown in the screenshot below.

Using the –no-wait Flag
If you are stopping a large VM (like a GPU-heavy N-series instance), the CLI might “hang” while it waits for the deallocation to complete. I prefer to fire-and-forget:
Code snippet
az vm stop --resource-group demo --name AzureLessonsLinuxVM --no-waitAfter executing the command above, I received the expected output, as shown in the screenshot below.

The --no-wait flag returns you to the command prompt immediately, while Azure handles the shutdown in the background.
Step 4: Advanced Batch Operations
This is where you show your true authority as an Azure administrator. Let’s say you want to stop every VM in a specific subscription that is currently running, perhaps as part of an emergency cost-cutting measure.
Stopping All Running VMs
I often use this snippet in my automation scripts:
- Find running VMs:
az vm list -d --query "[?powerState=='VM running'].name" -o tsv - Stop them: Combine the list with the stop command.
Identifying VM States
Before you act, you should always verify the current status. Use the --show-details flag (or -d for short) to see the Power State:
Code snippet
az vm list -d --query "[].{Name:name, State:powerState}" --output tableAfter executing the command above, I received the expected output, as shown in the screenshot below.

az vm get-instance-view --name AzureLessonsLinuxVM --resource-group demo --query "instanceView.statuses[1].displayStatus" -o tsvAfter executing the command above, I received the expected output, as shown in the screenshot below.

Typical Output:
VM runningVM deallocatedVM starting
Step 5: Automating with Auto-Shutdown
While manual CLI commands are great, sometimes you want the platform to do the work for you. You can actually configure the Auto-Shutdown schedule via the CLI. This is a lifesaver for those of us who forget to run our scripts on Friday afternoons.
Code snippet
az vm auto-shutdown --resource-group Sales-RG --name Prospect-DB --time 1800 --timezone "Eastern Standard Time"In the command above:
--time 1800sets the shutdown for 6:00 PM.--timezoneensures it aligns with your local office hours (e.g., “Pacific Standard Time” for Cali folks).
Best Practices
When managing Azure resources, there are a few “unwritten rules” I always follow to maintain professional standards:
- Tagging: Always tag your VMs with an
OwnerandEnvironment(Dev, Prod, Staging). Before you stop a VM, your script should check ifEnvironment == 'Prod'. Never stop a production server via an automated script! - Resource Groups: Organize your VMs by project or department (e.g.,
HR-Systems-RG). This makes batch-stopping via CLI much safer. - Service Principals: For automated scripts (like those running on a local server in Dallas), don’t use your personal login. Create a Service Principal with “Virtual Machine Contributor” rights.
- Logging: Always pipe the output of your CLI commands to a log file so you have an audit trail if a server doesn’t come back up as expected.
Video Tutorial
Summary
Mastering the az vm start and az vm stop Commands are the first step toward becoming a Cloud Power User. By moving away from the Portal and into the CLI, you’re not just saving time—you’re building the foundation for scalable, automated infrastructure.
Quick Review Table
| Goal | Command |
| Start a VM | az vm start -g [RG] -n [Name] |
| Stop & Deallocate | az vm stop -g [RG] -n [Name] |
| Check Status | az vm list -d -o table |
| Force Stop (No Wait) | az vm stop -g [RG] -n [Name] --no-wait |
You may also like the following articles:

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
