[Azure Automation] Migrate your scripts to Azure – Part 2

Posted by Florent Appointaire on October 5, 2017
Share on Facebook0Share on Google+0Share on LinkedIn4Share on Reddit9Tweet about this on Twitter0
No ratings yet.

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  🙂

Related materials:

Views All Time
6
Views Today
9

Please rate this

To download the software products, please, make your choice below. An installer link and a license key will be sent to the e-mail address you’ve specified. If you consider StarWind Virtual SAN but are uncertain of the version, please check the following document Free vs. Paid. The recent build of Release Notes. A totally unrestricted NFR (Not For Resale) version of StarWind Virtual SAN is available for certain use cases. Learn more details here.



Return to all posts

The dark side of converged storage networks
Accessing esxcli through PowerCLI
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.