Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

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

  • October 5, 2017
  • 6 min read
Cloud and Virtualization Architect. Florent is specializing in public, hybrid, and private cloud technologies. He is a Microsoft MVP in Cloud and Datacenter Management and an MCSE in Private Cloud.
Cloud and Virtualization Architect. Florent is specializing in public, hybrid, and private cloud technologies. He is a Microsoft MVP in Cloud and Datacenter Management and an MCSE in Private Cloud.

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  🙂

Found Florent’s article helpful? Looking for a reliable, high-performance, and cost-effective shared storage solution for your production cluster?
Dmytro Malynka
Dmytro Malynka StarWind Virtual SAN Product Manager
We’ve got you covered! StarWind Virtual SAN (VSAN) is specifically designed to provide highly-available shared storage for Hyper-V, vSphere, and KVM clusters. With StarWind VSAN, simplicity is key: utilize the local disks of your hypervisor hosts and create shared HA storage for your VMs. Interested in learning more? Book a short StarWind VSAN demo now and see it in action!