Azure Automation: how to create an Hybrid Worker Group

Questo articolo è disponibile anche in lingua italiana al seguente link: Azure Automation: configurare un hybrid worker – WindowServer.it

Among the various features present in Azure Automation, there is also the possibility to orchestrate scripts to run in the cloud or on-premises servers. The logic of Runbooks are a derivative from System Center Orchestrator, a great product that allows to execute operational flows on the basis of various conditions. With the slow demise of SCO, Automation has become more and more predominant, also thanks to the many scripts available on GitHub.

With Azure Automation you can access and shut down virtual machines, check and send notifications, check the status of critical services or, as we will see in this article, restart a server.

Before leaving, you must have met the following requirements:

  • Have an Azure subscription
  • Have created a Workspace in Log Analytics
  • You have created an Azure Automation profile
  • Having installed the agent LA inside the local machine
  • In order to execute commands within a virtual machine, it is necessary to create Hybrid Worker Groups, or rather a group of machines on which to launch tasks.

Hybrid Worker Groups cannot be created from Azure Portal but are populated when the onboarding script is run.

The first step is to download the New-OnPremiseHybridWorker.ps1 script from the PowerShell Gallery. Then open PowerShell – figure 2 – as administrator and launch the command Install-Script -Name New-OnPremiseHybridWorker

NB: In case you receive any error messages relating to NuGet 2.8.x, it is possible that TLS 1.2 is not active for the PowerShell part; in this case, launch the command [Net.ServicePointManager] :: SecurityProtocol = [Net.SecurityProtocolType] :: Tls12 and restart the PowerShell console.

It is time to launch the agent onboarding with Azure Automation with the following script, which will have to bring a result similar to figure 3.

C:\Program Files\WindowsPowerShell\Scripts

$NewOnPremiseHybridWorkerParameters = @{
  AutomationAccountName = "automationname"
  AAResourceGroupName   = "ResourceGroupAA"
  OMSResourceGroupName  = "ResourceGroupLogAnalytics"
  HybridGroupName       = "GroupName"
  SubscriptionID        = "AzureSubscirption"
  WorkspaceName         = "LogAnalyticsName"
}
.\New-OnPremiseHybridWorker.ps1 @NewOnPremiseHybridWorkerParameters

After a few minutes the computer will be inserted into the Azure group – figure 4.

RunBook Creation

The runbook, in this case, is very simple and consists in restarting the machines present in that Hybrid Worker.

By clicking on the Edit button, you can edit the script in PowerShell format – figure 6.

Save and publish the script. Then prepare the schedule indicating that the target run will be the newly created Hybrid Worker – figure 7.

Conclusions

Azure Automation is certainly a useful tool for running scripts of various kinds and replaces the old on-premises platforms, centralizing management within Azure. Remember that the first 500 minutes, monthly, are free and that should be a reason to use it.

#DBS