Type something to search...
How to shut down an idle virtual machine in Azure

How to shut down an idle virtual machine in Azure


Definition

Managing cloud costs effectively is crucial for organizations. One of the biggest cost drivers in the cloud is the presence of idle virtual machines (VMs) that continue to run even when they are not needed. Instead of manually shutting down these VMs, you can use Azure Automation and alerts to automatically shut down them when they are idle. Here’s how to configure this automation in Azure.


Prerequisites

Licenses required

  • An Azure subscription.

Azure resources

  • A deployed virtual machine.

Administrator role

  • An account with the Contributor or Owner role on the Azure subscription.

Step 1 : Sign in to the Microsoft Azure portal

Sign in to the Microsoft Azure portal by opening your web browser to https://portal.azure.com.


Step 2 : Create an automation account

In the search bar at the top of the screen, type Automation account, and click the proposed menu.

image

Fill out the basic information (subscription, resource group, name, and region) for your account.

image

Check the System assigned box.

image

Check the Public access box.

image

Optionally, you can attach tags. Check the January 2025 post HERE in which I talked about tags.

image

Your account is now created.

image


Step 3 : Create an alert to detect inactive VMs

In the search bar at the top of the screen, type Virtual machines and click the proposed menu.
All your virtual machines will be displayed; in my case there is only one (a Windows 10 PC).

In the left menu, click Monitoring, then Alerts and Create custom alert rule.

image

Choose CPU Percentage as signal, set the threshold (I put 2% for the example) and the check frequency (15 minutes in my case).

image


Step 4 : Create an action to turn the VMs off

Click the Actions tab, then Create action group.
Fill out the basic information (subscription, resource group, region, and action name) for your action.

image

Choose the type of notification. I have configured the notification by email, but it is possible to do it via SMS.

image

Choose the Stop VM action and the automationaccount01 account created in step 2.

image


Step 5 : Complete the detection alert

Fill out the basic information (subscription, resource group, severity, alert and description) for your alert.

image

The configuration is now complete.

image


Where to see the result ?

We can see here that my VM is on (running) because the signal (CPU less than 2% for 15 minutes) has not yet been reached. Azure monitors the CPU usage of the VM.

image

As soon as the signal is reached, I receive the notification email (or SMS).

image

And I can see that my VM is now turned off (deallocated).

image

Click Alerts to validate that the programmed action is indeed the cause of the VM shutdown.

image


Conclusion

Using Azure Monitor Alerts & Automation to automatically shut down inactive VMs provides dynamic savings without manual effort. This method is particularly useful for environments where VM usage is unpredictable. By following these steps, you can optimize your cloud costs and improve the efficiency of your resource management.

You now know how to schedule an alert to shut down an idle virtual machine.


Sources

Microsoft - Techcommunity

Microsoft Learn - Azure Monitor

Microsoft - Azure Monitor pricing


Did you enjoy this post ? If you have any questions, comments or suggestions, please feel free to send me a message from the contact form.

Don’t forget to follow us and share this post.

Related Posts

How to add tags to an Azure virtual machine

How to add tags to an Azure virtual machine

Definition Tags in Azure are customizable labels (in the form of metadata) that you can apply to your resources to organize and manage your cloud environments more efficiently. They play a

Read More