Showing results for 
Search instead for 
Did you mean: 

Scheduled Start / Stop of Azure VMs to reduce costs.

I think everyone has the same problem: the Azure Virtual machines runs overnight when nobody is working on it and the costs are growing.

To reduce the cost for virtual machines in Azure Microsoft Flow can be used to schedule the start/stop processes of each Virtual Machine or complete resource groups in Azure.

For this there are to setups needed to be setup: Azure Automation Account and the Flow.


Azure Automation Accounts


recurrence_start_azure_vm_10.PNGThe First steps are done in Azure.


In Azure the service "Automation Accounts" can be used for start/stop processes.


The service can easily be found by the search function in the top pane. 




In the Automation Accounts a new Account will be created by choosing "+ ADD".

It is necessary to choose the Subscription in which the virtual machines are located.

If there are virtual machines in different subscriptions for each subscription an Automation Account is needed.




In the next window the name of the Account and the used Subscription and the name of the resource group is defined.

The Location should be in the same location as the subscription is and for "create azure run as account" should be Yes.




After the account is created there the runbooks for start/stop processes has to be defined.

In the Azure Automation Account the runbooks can be found in the details.:




For this process the needed templates can be found in the gallery:




In the gallery there are the needed runbooks available:

The "Stop Azure V2 VMs" and the "Start Azure V2 VMs".

Both of them are needed as a runbook in the Automation Account.




The Following steps are similar to the Stop and the Start Runbook.


After selecting the runbook template this template has to be imported into the Automation Account.




In the next window the name of the runbook and a description is defined.




The imported runbook need to be published to be available. For this the imported runbook has to be edit:




In the edit screen the button "publish" will publish the runbook to be activated.




These steps are the setup which has to be done before setup the flows. This setup has to be done only one time because all of the future VMs in the subscription can be used with this setup.


Please be aware that described steps are an template for you but you have to check everything while doing your setup.


Microsoft Flow

After the setup in Azure is finished the setup in Microsoft Flow can be done.

For this business case you have to setup only 2 steps for stop and 2 steps for start.

These steps are 95% similiar.

Only the runbook name and the recurrence hour are different.


Here an overview of the created flow which is now described how to setup.




Now the steps to stop a machine are described.


The first step is the trigger for the recurrence so that Flow knows when to run.


To setup this step there is a connector called "Schedule" and within this connector there is a trigger called "recurrence".


In the trigger there is the setup for the time and when the flow has to run. Here in this example the trigger runs once a day at 08:36 in the time zone UTC+01:00.




There are also options available to use another frequency.

If you choose weekly at the frequency you can choose on which weekdays the flow should run.

At the bottom there is a short preview of your setup is shown.


The next step in this flow is the action to do something.

Here the action is an action from the connector called "Azure Automation".

The action to do is the "create Job" action.

This action allows flow to create automated job in azure.

This job is defined through the selected runbook.

To setup this the new Action called Azure Automation is created within the flow.




In this setup the used credentials to allow flow to connect to azure are selected and the mentioned azure subscription is selected.

Then the resource group and the account of the needed Automation Action can be selected.

The needed runbook for the stop process is selected and in the fields "VM Name" and "ResourceGroupName" the information from the virtual machine which is to processed by this flow has to entered.


The same setup but with another runbook has to be done for the start process.


Please be aware that this is only an example and you have to test it on your own risk. TEst it first on test or development environment and not on production environments.

Hope you enjoy this flow.

Find more on my blog or follow me on Twitter

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc (
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor