This setting up Azure Automation by importing my custom RunBook that Start/Stop virtual machines based on tags

Requirement :

  1. Resource Group
  2. Virtual Machine

Source : https://github.com/hhazeley/AzureAutomation-StopStart

Example :

  • ResourceGroup : RGAutomation
  • Location : Southeast Asia
  • Virtual Machine Name : VMAutomate01 , VMAutomate02
  • Automation Account : ACAutomate
  • Script from github : AzureAutomation-StopStart-master ( before use please extract file )

Lab : Create resource Group

PS Azure:\> New-AzResourceGroup -Name RGAutomation -Location southeastasia

Lab : Create Virtual Machine

  1. Create command username and password generate a random password running scrip on command ( Bash )

USERNAME=azureuser

PASSWORD=$(openssl rand -base64 32) 

2. Create Virtual Machine by Command ( Bash )

az vm create \

 –name VMAutomate01 \

 –resource-group RGAutomation \

 –image Win2016Datacenter \

 –size Standard_DS2_v2 \

 –location SoutheastAsia \

 –admin-username $USERNAME \

 –admin-password $PASSWORD

3. Create Virtual machine by Power Shell

New-AzVm `

  -ResourceGroupName “RGAutomation” `

  -Name “VMAutomate02” `

  -Location “Southeast Asia” `

  -VirtualNetworkName “VMAutomate01VNET” `

  -SubnetName “VMAutomate01Subnet” `

  -SecurityGroupName “VMAutomate01NSG” `

  -PublicIpAddressName “VMAutomate02PiP”

Lab : Automation

  1. Create Automation Accounts

Home ==>browse ==> Automation ==> Automation Accounts


  • Automation Account : ACAutomate

See on Resource Group

Overview Automation account

Check script connection

Process Automation ==> Runbook ==>Import a runbook

Next step

Next step add Scrip Stop VM

Next step config Power shell script

Click script start on Runbooks ==>edit ==>

Param(

$AutomationRG = “My1StRG“, My1StRG = ResourceGroup Name

$AutomationAcct = “StopStart“, My1StRG = Automation Account Name


after

Next step config Power shell script

Click script startVM on Runbooks ==>edit ==>click Publish

Next step config Power shell script

Click script Stop on Runbooks ==>edit ==>

Param(

$AutomationRG = “My1StRG”, My1StRG = ResourceGroup Name

$AutomationAcct = “StopStart”, My1StRG = Automation Account Name

Save ==> Publish

Next step config Power shell script

Click script StopVM on Runbooks ==>edit ==>click Publish

Lab : add taged to Virtual Machine

Test Runing Script

to ResoureGroups ==>Automation account ==>

Runbooks ==>Click Start ( for turn on VM )

Check Job process

Overview

Check Virtual Machine

Script runing status done

Test runing Script Stop Virtual Machine

ResouceGroup ==> click Automation account==> Runbook ==> Click Stop script ==>

Start process ==>OK

after runing script ==>for check script running

Check Job

Check Virtual Machine

Comment

ทิ้งคำตอบไว้

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.