Start PowerShell Script Runbook on Hybrid Worker with Azure Arc

Written by 10:08 am Microsoft Azure, PowerShell • 2 Comments

Run PowerShell Scripts with Azure Automation Hybrid Workers on-premises using Azure Arc

If you want to automate your on-premises environment Azure Arc enabled Server is a great offering to onboard Azure management services such as Azure Monitor, Defender for Cloud, and many others. One of the integrations is with Azure Automation Hybrid Worker. This allows you to run Azure Automation PowerShell or Phyton runbooks on-premises directly on your Azure Arc enabled servers. In this blog post we are going to have a look on how you can run your PowerShell scripts on-premises using Azure Automation Hybrid Workers with Azure Arc.

Azure Automation Hybrid Runbook Worker with Azure Arc
Azure Automation Hybrid Runbook Worker with Azure Arc

Create Azure Automation Account

First, you will need to create an Azure Automation account, this is very straight forward.

Create Azure Automation Account
Create Azure Automation Account

On the Advanced tab, you can configure the managed identity option for your new Automation account. This is the identity under which the runbook can sign in into Azure PowerShell for example. In this case I am going to use a System assigned identity.

Check out Microsoft Docs for more information.

Connect Server to Azure using Azure Arc

To connect a server running on-premises or at another cloud provider to Azure using Azure Arc, you can simply go to the Azure Portal to the Azure Arc Center and select Azure Arc enabled servers. Here you can click on the “Add” button and you can run through the onboarding wizard. To learn more, check out my blog post here on connect a Hybrid Server to Azure using Azure Arc.

Azure Arc Onboarding Script
Azure Arc Onboarding Script

You learn more about onboarding Azure Arc enabled servers here on Microsoft Docs.

Create Hybrid Worker Group

Now you can create and maintain hybrid worker groups for running hybrid jobs, which provides resiliency to run jobs across multiple hybrid workers. With extension-based hybrid worker (preview), both Azure machines and non-Azure machines (through Arc enabled server) can be managed through ARM templates and policies.

To create you a hybrid worker which can be Windows and Linux servers, you provide a name, and you can also add custom credentials to run the script.

Create Hybrid Woker Group
Create Hybrid Woker Group

You will also select the hybrid workers (Azure Arc enabled Servers) you want to run the scripts on.

Hybrid Worker Group Azure Arc enabled Servers
Hybrid Worker Group Azure Arc enabled Servers

This process will automatically install the Hybrid Worker Extension.

User Hybrid Worker Groups
User Hybrid Worker Groups

You can always add or remove hybrid workers from the hybrid worker group.

Azure Automation hybrid Workers with Azure Arc-enabled server
Azure Automation hybrid Workers with Azure Arc-enabled server

You can learn more here on Microsoft Docs.

Create a new Azure Automation Runbook

You can create a new Azure Automation PowerShell runbook, which will host the script you are going to run or schedule. Depending on what version of runbook runtime you are choosing you need to prepare the host by installing PowerShell 7 or Python.

Azure Automation PowerShell Runbook
Azure Automation PowerShell Runbook

Here you can now add your PowerShell script.

PowerShell Script
PowerShell Script

Run and schedule PowerShell scripts as Azure Automation runbooks on hybrid workers connected with Azure Arc

You can now run and schedule PowerShell scripts as Azure Automation runbooks on hybrid workers connected with Azure Arc. When you run the runbook, you can now select on which hybrid worker group this script should be running.

Start PowerShell Script Runbook on Hybrid Worker with Azure Arc
Start PowerShell Script Runbook on Hybrid Worker with Azure Arc

Now you can monitor the job and the output:

Azure Arc Hybrid Runbook Output
Azure Arc Hybrid Runbook Output

You can also schedule a runbook on a specific schedule. Simply click on “Link to schedule” and select or create a schedule and set parameters as well as run book settings to run on the Hybrid Runbook Workers.

Schedule and Configure Hybrid Runbook settings
Schedule and Configure Hybrid Runbook settings

Example for schedule:

Create Runbook Schedule
Create Runbook Schedule

Conclusion

I hope that post was helpful and showed you how you can run PowerShell Scripts with Azure Automation Hybrid Workers on-premises using Azure Arc. Let me in the comments if you have any questions.

Tags: , , , , , , , , , , , Last modified: November 21, 2022
Close Search Window
Close