Azure Automation

Posted: November 21, 2017 in Azure

Microsoft Azure Automation provides a way to automate the manual, long-running, and frequently repeated tasks.

In this post we’ll automate turning off Azure VM

We first need to create automation account

An Automation account serves as a container of automation components, such as Azure PowerShell modules, scripts, and workflows, or credentials and
certificates used to connect to other Azure services

In Azure portal click New-Monitring + Management-Automation

1

Specify name,check Create Azure Run AS account

2

In account properties click Variables under Shared Resources

3

In values specify VM name

4

Create another variable for resource group

5

6

Creating runbooks

A runbook is a set of tasks that perform some automated process in Azure Automation. It may be a simple process such as starting a virtual machine and creating a log entry, or you may have a complex runbook that combines other smaller runbooks to perform a complex process across multiple resources or even multiple clouds and on-premises environments.It’s based on Windows PowerShell or Windows PowerShell Workflow, so they do anything that PowerShell can do.

In Automation account properties click Runbooks under Process Automation-Add a runbook

7

I imported powershell script which stops Azure VM

workflow Stop-AzureVMs-Workflow
{
$c = Get-AutomationConnection -Name 'AzureRunAsConnection'
Add-AzureRmAccount -ServicePrincipal -Tenant $c.TenantID -ApplicationID $c.ApplicationID -CertificateThumbprint $c.CertificateThumbprint
$vm0 = Get-AutomationVariable -Name 'VM00'
$vm1 = Get-AutomationVariable -Name 'VM01'
$rg = Get-AutomationVariable -Name 'ResourceGroup'
Parallel
{
Stop-AzureRmVM -Name $vm0 -ResourceGroupName $rg -Force
Stop-AzureRmVM -Name $vm1 -ResourceGroupName $rg -Force
}
}

 

8.PNG

 

In runbook properties click Edit

 

9

Click publish

 

10

Click Start

 

11

Click output

 

12

Output from Runbook is shown-VM is shutdown

 

13

 

 

14.PNG

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s