Introduction

For a tester or a developer, the cost for a lab virtual machine is not something negligible because it has a daily cost. The solution to this problem is the Start/Stop VMs Automation in Azure.

Before we start, we should know.
  1. The Automation Account must be in the same Subscription with the Virtual Machines
  2. The solution must be deployed in any region that Log Analytics workspace is supported
  3. The Azure Run As Account must be a Service Administrator

Deploy The Solution From Scratch

Search For The Solution

The first we should do is to search for the [Start/Stop VMs during off-hours] solution.

So the steps are:
  1. Search for the [Start/Stop VMs during off-hours] solution
  2. Select the result [Start/Stop VMs during off-hours]
  3. Click Create to begin the solution deployment

Back to top



Create Log Analytics Workspace

The first from the next steps is to Create a Log analytics workspace if it doesn't already exist.

  1. From the Add Solution blade, select *Workspace
  2. We don’t have an OMS Workspace, so we click Create New Workspace to create a new one.
  3. In the new blade called Log analytics workspace fill in all the needed information for the deployment, as the below image shows.



Setting  Value 
OMS Workspace  Type a name for the OMS Workspace
Subscription  Select an Azure Subscription 
Resource Group  Select an existing or create a new Resource Group 
Location  Select a location for the resources

Create Automation Account

At the next step, we must create an Automation account. This account will be the one that the solution will run

  1. Select *Automation account
  2. We don’t have any automation account to select, so we must create a new by clicking the Create an Automation account link
  3. In the Add Automation Account blade, we type all the necessary information for the automation account and we click Create.



Set-up The Configuration Parameters

The last step to begin the deployment is to set-up to *configure parameters of the solution.
  1. Select the *configure parameters
  2. Fill in the necessary details into the Parameters blade, and click Create.


Setting  Value 
VM runbook - Target ResourceGroup Names(string) By default all resource group in the subscription will be included, else type the resource group that contains the Virtual Machines.
VM runbook - VM Exclude List (string) The default value is none, type the VM names to be excluded from the management operation. Separate name by using a comma(,).
Schedule - Daily Start Time Enter time for starting VMs by resource group. The schedule will be reflected as UTC in the automation account. 
Schedule - Daily Stop Time Enter time for stopping VMs by resource group. The schedule will be reflected as UTC in the automation account.
Email functionality - Receive Email Notifications (string) Azure Monitor features are used to send email notifications, Select Yes/No to enable or disable this.
Email functionality - Email Addresses (string) Enter the recipients of the email. Separate names by using a comma(,).

Back to top


The Runbook

The Runbook that is used to Start and Stop Virtual Machine(s) is the ScheduledStartStop_Parent.



Set Schedules

From the Runbook left blade Resources - Schedules, we can view the active Schedules (Start and Stop the VM) or we can Add a new schedule by clicking "+Add a schedule"

Schedule

On this step select an existing schedule or create a new one, In the image below there is an existing Schedule to Start Virtual Machine.




Parameters and run settings


At the "parameters and run settings" step type the Action, VM Name and click OK.


Back to top


Test The Runbook

We can also test the runbook to see if there is any error on the executed actions using the Test Pane.

To begin Test Pane select Edit



In the next step select Test pane



Type the Parameters as the image below shows, and click Start



The Runbook Test begin and we are able to view the results and the error messages as the code below shows.

Completed

Logging in to Azure...
 
Environments                                                                                                           
------------                                                                                                           
{[AzureChinaCloud, AzureChinaCloud], [AzureCloud, AzureCloud], [AzureGermanCloud, AzureGermanCloud], [AzureUSGovernme...
Authenticating Classic RunAs account
Get connection asset: AzureClassicRunAsConnection
Getting the certificate: AzureClassicRunAsCertificate
Authenticating to Azure with certificate.
Runbook Execution Started...
VM List is given to take action (Exclude list will be ignored)...
The current action is start
Calling the ScheduledStartStop_Child wrapper (Action = start)...
Performing the schedule start for the VM : VMName using AzureRM
~Attempted the start action on the following VMs: VMName
Runbook Execution Completed...

Conclusion

In this post, we learned how to easy schedule Start-Stop Azure Virtual Machine(s). This is a great way to save money from the Test/Lab Azure Virtual Machines which must be up & running for the development teams. 

See Also


Back to top