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.
Create Azure Automation Account
First, you will need to create an Azure Automation account, this is very straight forward.
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.
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.
You will also select the hybrid workers (Azure Arc enabled Servers) you want to run the scripts on.
This process will automatically install the Hybrid Worker Extension.
You can always add or remove hybrid workers from the hybrid worker group.
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.
Here you can now add your 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.
Now you can monitor the job and the 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.
Example for schedule:
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: automation, Azure Arc, Azure Automation, Cloud, Hybrid, Hybrid Cloud, Microsoft, Microsoft Azure, PowerShell, Server, Windows Server, Worker Last modified: November 21, 2022