Use Teams Lists (SharePoint) and Power Automate to determine when to turn your Azure Virtual Machine
- Ómar Örn Magnússon
- Feb 17, 2021
- 1 min read
One customer wanted an easy way for the developers to control when the Azure dev machines are on, default they are now off until a time is set to turn them on and off.
First, the list is created
Add Server, ResourceGroup (choice), Subscription, Days of the week (Choice), Time on, Time Off, History, description to the list
Then add the Virtual servers to the list

Then we create a new Scheduled cloud flow and set it to run every hour (or more often)
Then we start by adding some compose action to get the hour with the expression startOfHour(utcNow(),'HH:mm')
then I created another expression if(equals(dayOfWeek(utcNow()),5),'Friday','') to get the weekday to number
then I get all the SharePoint items
then apply some expressions to match if the day and the time is equal to the items from the SharePoint list

For the on-time if(equals(outputs('Time-ON'),outputs('get_the_hour:min_or_HH:mm')),'timeonyes','')
Off-Time if(equals(outputs('Time-OFF'),outputs('get_the_hour:min_or_HH:mm')),'timeoffyes','')
and the weekday expression if(equals(outputs('dagur'),outputs('Day_of_the_week_number_to_the_day')),'dayyes','')
then I used the Switch and did case
dayyestimeonyes for the action to turn on the server
and dayyestimeoffyes for the turn of the server

And then i log the action to the description and history field by updating the SharePoint item
Hope this helps anyone else, please feel free to send me a line or any questions if there are any through any of the social media listed at the top.
Best regards Omar
Comments