How to Create Azure VM Scheduled Startup with Azure Automation

choubertsprojects

The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

The Azure Automation templates provide a way to create VM scheduled startups. This blog will show you the steps on how to do this with an example PowerShell script that can be downloaded for free at https://github.com/wilkinson-it-solutions/azure-startup/.

The “azure automation start/stop vms powershell” is a PowerShell script that allows users to manage Azure Virtual Machines. It can be used for scheduling startup, shutdown, and restart of VMs.

How to Create Azure VM Scheduled Startup with Azure Automation

Cost. When managing Azure resources, this is one of the things to keep in mind. Azure virtual machine utilization will most likely be the largest cost contributor when you create your Azure usage report. Creating an Azure VM schedule may be advantageous.

You should determine if your virtual machines must be up and operating at all times or whether some of them may be turned off on a set schedule to save money.

Stopping Azure VMs on a schedule is already possible. You may use this functionality to define a timetable for gently shutting down Azure VMs in order to deallocate them. But how can you plan the commencement of those Azure VMs programmatically?

Tags and Azure Automation may be used to establish an Azure VM scheduled start time. In this post, you’ll learn how to plan the launch of Azure virtual machines using Tags and a PowerShell Runbook.

Requirements

You must fulfill these prerequisites if you want to do more than simply read this article and try out the examples.

Making Advance Plans

There are aspects of each project that must be planned for. Your operational variables, such as the virtual machine name(s), resource group, automation account, and tags, must all be defined.

The following will be utilized in this article. It is suggested that you make a comparable list for your surroundings.

  • ATA is a resource group.
  • AzVM1, AzVM2 are the virtual machine names.
  • PS-Demo-AA is the automation account name.
  • Azure-VM-Schedule-Start-6am Automation RunBook
  • StartTime=”6 a.m.”
  • 06:00:00: 06:00:00: 06:00:00: 06:00:

The Azure VM Schedule Tag is assigned.

The virtual machines must be marked in order for those with Azure VM schedules to start as part of the automated runbook. To add tags to your target Azure VMs, follow the steps below.

The Azure Portal and PowerShell are used to assign the Azure VM schedule tag in the following sections.

The Azure VM Schedule Tag is assigned. (Azure Portal)

It’s simple to apply tags to many virtual machines using the Azure Portal. Log in to the Azure Portal first. Then go to Virtual Machines and choose the virtual machines you want to tag. AzVM1 and AzVM2 are selected in the example below. After you’ve made your choice, click the Assign tags option.

Tags will be assigned to Azure Virtual Machines.Tags will be assigned to Azure Virtual Machines.

Then, when the Assign tags fly-out displays, type StartTime:6am as the Name and Value for this new tag. Then choose Save.

Tag Azure virtual machinesTag Azure virtual machines

The Azure VM Schedule Tag is assigned. (Azure PowerShell)

While utilizing the Azure Portal is simple and handy, you’re better off using PowerShell to tag hundreds of VMs.

If you’d rather use PowerShell to add tags to your Azure VMs, use the code below. Make that the -Name and -ResourceGroupName arguments are set to the names of your virtual machine and resource group, respectively.

## Get the attributes of the Virtual Machine Get-AzVM -Name AzVM1 -ResourceGroupName ATA $azVM = Get-AzVM ## Get the tags that already exist. $azVM.Tags = $tags ## Insert a new tag @StartTime=”6am” $tags += Set-AzResource -Name $azVM.Name -ResourceGroupName ## Apply the new tag collection to the Virtual Machine -ResourceType $azVM.ResourceGroupName -Tags $azVM.Type $tags

You should see something like the picture below after executing the code above in Azure PowerShell.

The Azure virtual machine is being tagged.The Azure virtual machine is being tagged.

If you need to generate Azure VM schedule tags on additional virtual machines, follow the instructions above but change the target virtual machine’s name. If you wish to go any farther, you may modify the script to accept several virtual machines as input and tag them all at once.

The Azure Automation Runbook is created.

A runbook may be made in two ways. The first method is to construct the runbook first, then import the script. The second option is to import the script, which will generate a new runbook if one does not already exist. You’ll learn how to utilize the latter in both the Portal and PowerShell in this section.

PowerShell Script Creation

It’s now time to build the Azure VM scheduled starting script. The new Azure Automation runbook will then import this code.

Copy the code below into your text editor or IDE and save it as C:ATAAzure-VM-Schedule-Start-6am.ps1. To learn what each line of code does, read the comments at the top of each line.

$azConn = Get-AutomationConnection -Name ‘AzureRunAsConnection’ ## Get the Azure Automation Account Information $azConn = Get-AutomationConnection -Name ‘AzureRunAsConnection’ ## Add -ServicePrincipal -Tenant Add-AzureRMAccount -ApplicationId $azConn.ApplicationId -CertificateThumbprint $azConn.ApplicationId $azConn.CertificateThumbprint ## Get the Azure VMs that have tags that match the value ‘6am’. Where-Object

Cost. When managing Azure resources, this is one of the things to keep in mind. Azure virtual machine utilization will most likely be the largest cost contributor when you create your Azure usage report. Creating an Azure VM schedule may be advantageous.

You should determine if your virtual machines must be up and operating at all times or whether some of them may be turned off on a set schedule to save money.

Stopping Azure VMs on a schedule is already possible. You may use this functionality to define a timetable for gently shutting down Azure VMs in order to deallocate them. But how can you plan the commencement of those Azure VMs programmatically?

Tags and Azure Automation may be used to establish an Azure VM scheduled start time. In this post, you’ll learn how to plan the launch of Azure virtual machines using Tags and a PowerShell Runbook.

Requirements

You must fulfill these prerequisites if you want to do more than simply read this article and try out the examples.

Making Advance Plans

There are aspects of each project that must be planned for. Your operational variables, such as the virtual machine name(s), resource group, automation account, and tags, must all be defined.

The following will be utilized in this article. It is suggested that you make a comparable list for your surroundings.

  • ATA is a resource group.
  • AzVM1, AzVM2 are the virtual machine names.
  • PS-Demo-AA is the automation account name.
  • Azure-VM-Schedule-Start-6am Automation RunBook
  • StartTime=”6 a.m.”
  • 06:00:00: 06:00:00: 06:00:00: 06:00:

The Azure VM Schedule Tag is assigned.

The virtual machines must be marked in order for those with Azure VM schedules to start as part of the automated runbook. To add tags to your target Azure VMs, follow the steps below.

The Azure Portal and PowerShell are used to assign the Azure VM schedule tag in the following sections.

The Azure VM Schedule Tag is assigned. (Azure Portal)

It’s simple to apply tags to many virtual machines using the Azure Portal. Log in to the Azure Portal first. Then go to Virtual Machines and choose the virtual machines you want to tag. AzVM1 and AzVM2 are selected in the example below. After you’ve made your choice, click the Assign tags option.

Tags will be assigned to Azure Virtual Machines.Tags will be assigned to Azure Virtual Machines.

Then, when the Assign tags fly-out displays, type StartTime:6am as the Name and Value for this new tag. Then choose Save.

Tag Azure virtual machinesTag Azure virtual machines

The Azure VM Schedule Tag is assigned. (Azure PowerShell)

While utilizing the Azure Portal is simple and handy, you’re better off using PowerShell to tag hundreds of VMs.

If you’d rather use PowerShell to add tags to your Azure VMs, use the code below. Make that the -Name and -ResourceGroupName arguments are set to the names of your virtual machine and resource group, respectively.

## Get the attributes of the Virtual Machine Get-AzVM -Name AzVM1 -ResourceGroupName ATA $azVM = Get-AzVM ## Get the tags that already exist. $azVM.Tags = $tags ## Insert a new tag @StartTime=”6am” $tags += Set-AzResource -Name $azVM.Name -ResourceGroupName ## Apply the new tag collection to the Virtual Machine -ResourceType $azVM.ResourceGroupName -Tags $azVM.Type $tags

You should see something like the picture below after executing the code above in Azure PowerShell.

The Azure virtual machine is being tagged.The Azure virtual machine is being tagged.

If you need to generate Azure VM schedule tags on additional virtual machines, follow the instructions above but change the target virtual machine’s name. If you wish to go any farther, you may modify the script to accept several virtual machines as input and tag them all at once.

The Azure Automation Runbook is created.

A runbook may be made in two ways. The first method is to construct the runbook first, then import the script. The second option is to import the script, which will generate a new runbook if one does not already exist. You’ll learn how to utilize the latter in both the Portal and PowerShell in this section.

PowerShell Script Creation

It’s now time to build the Azure VM scheduled starting script. The new Azure Automation runbook will then import this code.

Copy the code below into your text editor or IDE and save it as C:ATAAzure-VM-Schedule-Start-6am.ps1. To learn what each line of code does, read the comments at the top of each line.

## Get the Azure Automation Acount Information $azConn = Get-AutomationConnection -Name ‘AzureRunAsConnection’ ## Add the automation account context to the session Add-AzureRMAccount -ServicePrincipal -Tenant $azConn.TenantID -ApplicationId $azConn.ApplicationId -CertificateThumbprint $azConn.CertificateThumbprint ## Get the Azure VMs with tags matching the value ‘6am’ $azVMs = Get-AzureRMVM | Where-Object {$_.Tags.StartTime -eq ‘6am’} ## Start VMs $azVMS | Start-AzureRMVM

That’s it. You’ve written the PowerShell script that the Azure automation runbook will utilize later.

The Azure Automation Runbook is created. (Azure Portal)

To create a new runbook, navigate to Automation Accounts in the Azure Portal and choose the automation account where the runbook will be generated. PS-Demo-AA is the name of the automation account in this case.

Then, under the Process Automation section, go to the Runbooks blade and select Upload a runbook.

Import a scheduleImport a schedule

The Import a schedule fly-out would appear. Click the Browse button and locate the PowerShell script created earlier with the name C:ATAAzureVm6amStartTime.ps1. Once the file is added, click on Create.

Choose a script for the runbook.Choose a script for the runbook.

After the runbook import is complete, the new Azure-VM-Schedule-Start-6am runbook should appear in the automation account.

There is a new runbook prepared.There is a new runbook prepared.

The runbook properties page will appear when you click on the new Azure-VM-Schedule-Start-6am runbook. To validate that your code was imported, click the Edit button.

The new attributes of the runbookThe new attributes of the runbook

The PowerShell script is immediately imported into the runbook, as seen in the picture below.

Runbook code in PowerShellRunbook code in PowerShell

The Azure Automation Runbook is created. (Azure PowerShell)

The next step is to import the PowerShell script Azure-VM-Schedule-Start-6am.ps1 into a new runbook after saving it.

The script C:ATAAzure-VM-Schedule-Start-6am.ps1 will be imported into a new PowerShell runbook titled Azure-VM-Schedule-Start-6am using the code below. Copy and execute the code below in PowerShell.

@ $runBookSplat ‘Azure-VM-Schedule-Start-6am’ as the name AutomationAccountName = ‘PS-Demo-AA’ ResourceGroupName = ‘ATA’ ‘C:ATA’ as a path Azure-VM-Schedule-Start-6am.ps1 ‘PowerShell’ as the type $true = $force @runBookSplat Import-AzAutomationRunbook

The screenshot below exhibits a similar outcome after executing the code above.

Create a new PowerShell runbook by importing it.Create a new PowerShell runbook by importing it.

The Azure Automation Runbook is being tested (Azure Portal)

By default, runbooks are prepared as drafts. This gives you additional time to test your runbook before it goes live.

Open the Azure-VM-Schedule-Start-6am runbook in the Portal’s Edit PowerShell Runbook to test it. Then choose the Test pane option.

Choose the Test pane option.Choose the Test pane option.

To begin testing, click the Start button after the Test pane is open. Wait until the runbook testing is finished before looking at the output stream.

The PowerShell script is being tested.The PowerShell script is being tested.

The runbook test was finished without problems, as shown by the above result. Furthermore, the VMs that are the targets of this runbook should now be launched when you check the list.

The automated runbook is used to launch the Azure virtual machines.The automated runbook is used to launch the Azure virtual machines.

The Runbook’s Publication and Scheduling

So you’ve developed the runbook and tested it to make sure it works as expected. The only thing left is to make sure the runbook is published in Azure. It will run every day at 6:00 a.m.

A schedule is a shared resource or asset in Azure Automation. One or more runbooks may utilize or be connected to assets. To put it another way, making a schedule is not the same as assigning one to a runbook. A schedule may only connect to a published runbook, not a draft.

You’ll learn how to design a schedule, publish a runbook, and connect the schedule to the published runbook in the following sections.

Making a Timetable (Azure Portal)

Go to your Automation Account in the Azure Portal, such as PS-Demo-AA, to establish a schedule in this example. Then, under the Shared Resources area, click to Schedules. Click The button to add a schedule once the Schedules blade is open.

The button to add a scheduleThe button to add a schedule

Flyer for the new schedule should show on the page’s right-hand side. Fill in the blanks to create a new timetable. The schedule being prepared in this example is as follows.

  • Name: Azure VM 6AM Daily Scheduled Startup
  • Starts at 6:00 a.m. on August 24, 2020
  • Philippines time zone
  • Recurrence: The recurrence of something.
  • 1 day recurrence
  • Expiration date: No

Click Create after you’ve finished entering your chosen schedule parameters.

Flyer for the new scheduleFlyer for the new schedule

The establishment of a new schedule would then show in the list of schedules, indicating that it was successful.

In the Azure Portal, a new schedule asset is generated.In the Azure Portal, a new schedule asset is generated.

Making a Timetable (Azure PowerShell)

Use the code below to generate the new schedule asset using PowerShell instead of the Portal. Change the schedule attributes’ values as necessary.

# Create the parameters for the timetable. @ $azSchedule ‘Azure VM Scheduled Startup 6AM Daily’ is the name of the VM. ‘Asia/Manila’ as TimeZone (Get-Date ‘August 24, 2020 06:00:00 +08:00’) StartTime 1 day interval AutomationAccountName = ‘PS-Demo-AA’ ResourceGroupName = ‘ATA’ # Make a schedule. New @azSchedule -AzAutomationSchedule

Note: The TimeZone value has already been given. Despite this, the StartTime contains the timezone offset. This is because when the schedule is made for the first time, the StartTime value does not automatically consider the TimeZone.

You should get a similar result after executing the following code in PowerShell, as seen in the picture below. Navigate to the runbook on the Azure Portal and open it in Edit mode.

In Azure PowerShell, a new schedule asset is generated.In Azure PowerShell, a new schedule asset is generated.

The Runbook’s Publication (Azure Portal)

Navigate to the runbook and open it in Edit mode to publish it on the Azure Portal.

In Edit mode, open the runbook.In Edit mode, open the runbook.

Click the Publish button once the runbook is open in the editor. You may be asked if you want to Publication of the runbook or not. To proceed, choose Yes.

Publication of the runbookPublication of the runbook

You’ll note that the status of the runbook has changed from New to Published once you’ve published it.

The Azure Portal is used to publish the Runbook.The Azure Portal is used to publish the Runbook.

The Runbook’s Publication (Azure PowerShell)

Azure PowerShell may also be used to publish runbooks. You’ll need to use the code below, but update the -Name, -AutomationAccountName, and -ResourceGroup parameter values to match your values.

Publish-AzAutomationRunbook’-Name ‘Azure-VM-Schedule-Start-6am”-AutomationAccountName ‘PS-Demo-AA’

The anticipated output after performing the Publish-AzAutomationRunbook command is shown below.

Azure PowerShell is used to publish the runbook.Azure PowerShell is used to publish the runbook.

You’ve now released the runbook. You may now connect the runbook to a schedule.

Adding a Routine to the Runbook (Azure Portal)

The Azure VM Scheduled Startup 6AM Daily schedule that was previously developed may now be connected to the published runbook. In the Overview blade of the runbook, click the Schedule (link) button to link the schedule.

Schedule (link)Schedule (link)

Then choose Connect your runbook to a schedule. from the drop-down menu. There will be a list of available schedules shown.

Connect your runbook to a schedule.Connect your runbook to a schedule.

Then, choose the schedule you want to attach to the runbook, such as Azure VM Scheduled Startup 6AM Daily in this case.

Choose a timetable from the list.Choose a timetable from the list.

To finalize tying the schedule to the runbook, click OK after selecting the schedule.

Using the Azure Portal, connect the runbook to a schedule.Using the Azure Portal, connect the runbook to a schedule.

Adding a Routine to the Runbook (Azure PowerShell)

When done through the Azure Portal, the command below accomplishes the same effect as attaching a schedule to a runbook. Change the values of the -Name, -ScheduleName, -AutomationAccountName, and -ResourceGroupName parameters as needed.

‘ -Name ‘Azure-VM-Schedule-Start-6am”-ScheduleName ‘Azure VM Scheduled Startup 6AM Daily”-AutomationAccountName ‘ -ResourceGroupName ‘ATA’ PS-Demo-AA’

As you can see from the result below, your runbook has now been connected to the specified schedule.

Using Azure PowerShell, connect the runbook to a schedule.Using Azure PowerShell, connect the runbook to a schedule.

That’s it. Your Azure VM’s scheduled startup has been set up!

Summary

After reading this article, you should be able to design a runbook that automates the start-up of Azure virtual machines on a predetermined schedule using Tags and Azure Automation. You’ve mastered the following steps:

  • Tags are assigned to virtual machines.
  • Making a draft runbook, testing it, then releasing it.
  • Making a timetable and tying it to the published runbook.

The best part is that you now know how to do all of these tasks using both the Azure Portal and Azure PowerShell.

With the information in this post, you may want to develop a runbook to shut down or halt Azure VMs on a regular basis.

Additional Reading

.Tags.StartTime -eq ‘6am’ $azVMs = Get-AzureRMVM $azVMS | Start-AzureRMVM ## Start VMs $azVMS

That’s it. You’ve written the PowerShell script that the Azure automation runbook will utilize later.

The Azure Automation Runbook is created. (Azure Portal)

To create a new runbook, navigate to Automation Accounts in the Azure Portal and choose the automation account where the runbook will be generated. PS-Demo-AA is the name of the automation account in this case.

Then, under the Process Automation section, go to the Runbooks blade and select Upload a runbook.

Import a scheduleImport a schedule

The Import a schedule fly-out would appear. Click the Browse button and locate the PowerShell script created earlier with the name C:ATAAzureVm6amStartTime.ps1. Once the file is added, click on Create.

Choose a script for the runbook.Choose a script for the runbook.

After the runbook import is complete, the new Azure-VM-Schedule-Start-6am runbook should appear in the automation account.

There is a new runbook prepared.There is a new runbook prepared.

The runbook properties page will appear when you click on the new Azure-VM-Schedule-Start-6am runbook. To validate that your code was imported, click the Edit button.

The new attributes of the runbookThe new attributes of the runbook

The PowerShell script is immediately imported into the runbook, as seen in the picture below.

Runbook code in PowerShellRunbook code in PowerShell

The Azure Automation Runbook is created. (Azure PowerShell)

The next step is to import the PowerShell script Azure-VM-Schedule-Start-6am.ps1 into a new runbook after saving it.

The script C:ATAAzure-VM-Schedule-Start-6am.ps1 will be imported into a new PowerShell runbook titled Azure-VM-Schedule-Start-6am using the code below. Copy and execute the code below in PowerShell.

@ $runBookSplat ‘Azure-VM-Schedule-Start-6am’ as the name AutomationAccountName = ‘PS-Demo-AA’ ResourceGroupName = ‘ATA’ ‘C:ATA’ as a path Azure-VM-Schedule-Start-6am.ps1 ‘PowerShell’ as the type $true = $force @runBookSplat Import-AzAutomationRunbook

The screenshot below exhibits a similar outcome after executing the code above.

Create a new PowerShell runbook by importing it.Create a new PowerShell runbook by importing it.

The Azure Automation Runbook is being tested (Azure Portal)

By default, runbooks are prepared as drafts. This gives you additional time to test your runbook before it goes live.

Open the Azure-VM-Schedule-Start-6am runbook in the Portal’s Edit PowerShell Runbook to test it. Then choose the Test pane option.

Choose the Test pane option.Choose the Test pane option.

To begin testing, click the Start button after the Test pane is open. Wait until the runbook testing is finished before looking at the output stream.

The PowerShell script is being tested.The PowerShell script is being tested.

The runbook test was finished without problems, as shown by the above result. Furthermore, the VMs that are the targets of this runbook should now be launched when you check the list.

The automated runbook is used to launch the Azure virtual machines.The automated runbook is used to launch the Azure virtual machines.

The Runbook’s Publication and Scheduling

So you’ve developed the runbook and tested it to make sure it works as expected. The only thing left is to make sure the runbook is published in Azure. It will run every day at 6:00 a.m.

A schedule is a shared resource or asset in Azure Automation. One or more runbooks may utilize or be connected to assets. To put it another way, making a schedule is not the same as assigning one to a runbook. A schedule may only connect to a published runbook, not a draft.

You’ll learn how to design a schedule, publish a runbook, and connect the schedule to the published runbook in the following sections.

Making a Timetable (Azure Portal)

Go to your Automation Account in the Azure Portal, such as PS-Demo-AA, to establish a schedule in this example. Then, under the Shared Resources area, click to Schedules. Click The button to add a schedule once the Schedules blade is open.

The button to add a scheduleThe button to add a schedule

Flyer for the new schedule should show on the page’s right-hand side. Fill in the blanks to create a new timetable. The schedule being prepared in this example is as follows.

  • Name: Azure VM 6AM Daily Scheduled Startup
  • Starts at 6:00 a.m. on August 24, 2020
  • Philippines time zone
  • Recurrence: The recurrence of something.
  • 1 day recurrence
  • Expiration date: No

Click Create after you’ve finished entering your chosen schedule parameters.

Flyer for the new scheduleFlyer for the new schedule

The establishment of a new schedule would then show in the list of schedules, indicating that it was successful.

In the Azure Portal, a new schedule asset is generated.In the Azure Portal, a new schedule asset is generated.

Making a Timetable (Azure PowerShell)

Use the code below to generate the new schedule asset using PowerShell instead of the Portal. Change the schedule attributes’ values as necessary.

# Create the parameters for the timetable. @ $azSchedule ‘Azure VM Scheduled Startup 6AM Daily’ is the name of the VM. ‘Asia/Manila’ as TimeZone (Get-Date ‘August 24, 2020 06:00:00 +08:00’) StartTime 1 day interval AutomationAccountName = ‘PS-Demo-AA’ ResourceGroupName = ‘ATA’ # Make a schedule. New @azSchedule -AzAutomationSchedule

Note: The TimeZone value has already been given. Despite this, the StartTime contains the timezone offset. This is because when the schedule is made for the first time, the StartTime value does not automatically consider the TimeZone.

You should get a similar result after executing the following code in PowerShell, as seen in the picture below. Navigate to the runbook on the Azure Portal and open it in Edit mode.

In Azure PowerShell, a new schedule asset is generated.In Azure PowerShell, a new schedule asset is generated.

The Runbook’s Publication (Azure Portal)

Navigate to the runbook and open it in Edit mode to publish it on the Azure Portal.

In Edit mode, open the runbook.In Edit mode, open the runbook.

Click the Publish button once the runbook is open in the editor. You may be asked if you want to Publication of the runbook or not. To proceed, choose Yes.

Publication of the runbookPublication of the runbook

You’ll note that the status of the runbook has changed from New to Published once you’ve published it.

The Azure Portal is used to publish the Runbook.The Azure Portal is used to publish the Runbook.

The Runbook’s Publication (Azure PowerShell)

Azure PowerShell may also be used to publish runbooks. You’ll need to use the code below, but update the -Name, -AutomationAccountName, and -ResourceGroup parameter values to match your values.

Publish-AzAutomationRunbook’-Name ‘Azure-VM-Schedule-Start-6am”-AutomationAccountName ‘PS-Demo-AA’

The anticipated output after performing the Publish-AzAutomationRunbook command is shown below.

Azure PowerShell is used to publish the runbook.Azure PowerShell is used to publish the runbook.

You’ve now released the runbook. You may now connect the runbook to a schedule.

Adding a Routine to the Runbook (Azure Portal)

The Azure VM Scheduled Startup 6AM Daily schedule that was previously developed may now be connected to the published runbook. In the Overview blade of the runbook, click the Schedule (link) button to link the schedule.

Schedule (link)Schedule (link)

Then choose Connect your runbook to a schedule. from the drop-down menu. There will be a list of available schedules shown.

Connect your runbook to a schedule.Connect your runbook to a schedule.

Then, choose the schedule you want to attach to the runbook, such as Azure VM Scheduled Startup 6AM Daily in this case.

Choose a timetable from the list.Choose a timetable from the list.

To finalize tying the schedule to the runbook, click OK after selecting the schedule.

Using the Azure Portal, connect the runbook to a schedule.Using the Azure Portal, connect the runbook to a schedule.

Adding a Routine to the Runbook (Azure PowerShell)

When done through the Azure Portal, the command below accomplishes the same effect as attaching a schedule to a runbook. Change the values of the -Name, -ScheduleName, -AutomationAccountName, and -ResourceGroupName parameters as needed.

‘ -Name ‘Azure-VM-Schedule-Start-6am”-ScheduleName ‘Azure VM Scheduled Startup 6AM Daily”-AutomationAccountName ‘ -ResourceGroupName ‘ATA’ PS-Demo-AA’

As you can see from the result below, your runbook has now been connected to the specified schedule.

Using Azure PowerShell, connect the runbook to a schedule.Using Azure PowerShell, connect the runbook to a schedule.

That’s it. Your Azure VM’s scheduled startup has been set up!

Summary

After reading this article, you should be able to design a runbook that automates the start-up of Azure virtual machines on a predetermined schedule using Tags and Azure Automation. You’ve mastered the following steps:

  • Tags are assigned to virtual machines.
  • Making a draft runbook, testing it, then releasing it.
  • Making a timetable and tying it to the published runbook.

The best part is that you now know how to do all of these tasks using both the Azure Portal and Azure PowerShell.

With the information in this post, you may want to develop a runbook to shut down or halt Azure VMs on a regular basis.

Additional Reading

Azure Automation allows you to create Azure VM scheduled startups. This is done by using the “azure vm schedule reboot” command.

Related Tags

  • powershell script to auto start azure vm
  • start/stop vms during off-hours solution in azure automation
  • azure vm auto shutdown and startup
  • azure runbook start multiple vms
  • powershell script to start and stop multiple azure vm

Table of Content