Azure Automation logo

I recently looking for Azure Automation, from top to bottom. It’s why, in the next 2 articles, we will see how to use this tool, from A to Z:

Today, we will see how to migrate your On-Premises scripts, to Azure Automation. In my environment, I had 5 PowerShell scripts that ran with Schedule Tasks:

  • BackupOneDriveFolder: Backup my OneDrive folder to my Synology & on an Azure Blob Storage
  • BackuppfSenseConfiguration: Backup the configuration of my pfSense to Azure Blob Storage
  • CheckCertificateValidity: Check the validity of certificates of my websites
  • GetHyperVReport: Generate a report of my Hyper-V Server
  • UpdateS2SPublicIP: Update the public IP of my gateway, based on my NoIP

The principle is simple: migrate these 5 scripts to Azure Automation. I’ll need to use Azure and Hybrid Worker to run these scripts. The first step is to create your Schedules, based on what you are using with Tasks Scheduler. On your Azure Automation account, go to Schedules and create the schedule that you need:

Schedules Azure Automation account

The next step is to import module that you need to run your scripts, in the Modules part. If you use Hybrid Worker, install the right modules in the server that you will use for Hybrid connection:

Azure Automation modules

In the Assets part, create Variables that you will use in your scripts. Create Credentials too:

create Variables in Azure Automation

Azure Automation Credentials

When these prerequisites are ready, we can start the migration.

First, create a new Runbook, give it a name and choose PowerShell as type. Paste the PowerShell script associated with your script:

create new PowerShell Runbook

Adapt variables that use On-Prem a Username/Password or a key with the variable that you created or the credentials. You will use Get-AutomationVariable to get Variable and Get-AutomationPSCredential to get credentials. Normally, it’s the only part that you need to change. The script stays the same. You can test your script by using the Test Pane. And because I need to copy files to my Synology who is located On-Prem, I must use a Hybrid Worker:

test the script by using the Test Pane

When the script is finished, you should see this in the logs part:

Hybrid Worker group test results

Now that I know that the script is working correctly, just Save and Publish the script. You can link a schedule to this runbook, based on the schedule created before. Don’t forget to modify parameters by choosing if you want to run the script On-Prem with Hybrid Worker or on Azure. If your script is asking for parameters, you can complete them here:

Schedule Runbook

Do this for each script that you want to migrate. You can monitor your jobs that ran directly on the Jobs part of your Azure Automation account:

Azure Automation Jobs

Like in your PowerShell session, if something went wrong, you’ve logs:

Azure Automation Jobs errors

This process is very simple. After you migrated all of your scripts, you have only one console to manage scripts, logs, variables, etc… So, don’t hesitate to migrate  🙂

Views All Time
Views Today
Appreciate how useful this article was to you?
1 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 5
5 out of 5, based on 1 review
Back to blog
The following two tabs change content below.
Florent Appointaire
Florent Appointaire is Microsoft Engineer with 5 years of experience, specialized in Cloud Technologies (Public/Hybrid/Private). He is a freelance consultant in Belgium from the beginning of 2017. He is MVP Cloud and Datacentre Management. He is MCSE Private Cloud and Hyper-V certified. His favorite products are SCVMM, SCOM, Windows Azure pack/Azure Stack and Microsoft Azure.