Step 1: Login to Azure portal
Go to virtual machines then chose the instances you want to schedule and assign tags like this.
Step 2: Then select
Then Add account and create like this.
In my case Automation acount name is AutiShut1
AutoShut1
Then create runbook
Edit the runbook
Paste this code - change the tag accordingly
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
$VMs = Get-AzureRMVM | where {$_.Tags.Values -like '*6pmStart*'}
$VMs | Start-AzureRMVM
Write-Output $VMs.Name
Then click Save and Test pane
Then start to see the results.
Then Create schedule
Once you create the schedule link to the runbooks
No comments:
Post a Comment