Thursday, May 2, 2024
HomePowershellEasy methods to begin a Runbook on particular Hybrid Employee Azure Automation

Easy methods to begin a Runbook on particular Hybrid Employee Azure Automation


Disclaimer: this can be a work round that isn’t all the time helpful

I’m presently employed by a consumer who has one Hybrid Employee Group (and to whom we’re not allowed to make any changes).

There are runbooks that should work with the information from different runbooks, however as a result of the information is a lot and that is edited by one other workforce, they selected to generate the information first after which edit it in elements over 4 days.

This ensures that we now have 2 schedules the place one is for Runbook1 and the opposite is for Runbook2 the place schedule 2 begins 4 days in a row and continues to transform the information.

The drawback is that the information is saved on a Hybrid Employee after which the 2nd schedule begins on one other Hybrid Employee.

You’ll assume, why don’t you could have a file share?
Sadly, that’s not potential inside the environments both.

As a result of we’re imposed all types of restrictions, we are sometimes inventive.
Due to this I got here up with the next operate which is defined within the subsequent paragraph.


However what do I imply with the disclaimer?

Principally what the operate does is restart the Runbook till it runs on the proper Hybrid Employee.

That is nonetheless potential with two to 5 Hybrid Staff.
You probably have greater than 5, the query is whether or not you wish to do it that means? The possibility that the precise Hybrid Employee is chosen turns into smaller and smaller the extra Hybrid Staff you could have.

Perhaps it is best to simply have a look at one separate Hybrid Employee Group with one Hybrid Employee on which these kinds of runbooks can run.


Let’s begin a runbook on a particular Hybrid Employee in Azure Automation

So how does the operate work in brief?

When the runbook just isn’t operating on the Hybrid Employee you like.  
It’ll re-start the runbook and goes asleep for the worth described in parameter StartSleep.
As a result of the Runbook remains to be in sleep mode it would use a Hybrid Employee that has extra efficiency capability.
After the timer exceeded it would cease the runbook with assertion Exit.

Needless to say it may well go in to an infinite loop when the Hybrid Employee title is wrong! Learn the HybridWorker parameter rigorously.


Get the operate from Github

It’s essential to learn the HybridWorker parameter earlier than you begin utilizing this operate.

The operate is positioned in a Github repository.
You may copy the operate from Github and put it in Azure automation.

You may then dot supply the operate into your Runbook with the next:

. .Begin-SpecificHybridWorker.ps1

And simply name the operate by it’s title (operate title not runbook title):

Begin-SpecificHybridWorker -(together with parameters)

Let’s undergo the operate

The operate has 4 parameters:


Runbook (obligatory)

This parameter is obligatory, however it’s a simple one.

That is the runbook you wish to begin in Azure Automation.
The title is enough and also you don’t should put a .ps1 after it.

In my examples I’ll use the next:

. .Begin-SpecificHybridWorker.ps1
Begin-SpecificHybridWorker -Runbook 'Runbook1'

HybridWorkerGroup (obligatory)

This parameter is obligatory.

That is the HybridWorkerGroup that comprises the related Hybrid Employee.
You may see the group names and which Hybrid Staff are part of this group within the Azure portal.

Open the suitable Azure Automation setting and seek for and open Hybrid Employee Teams.

How to start a runbook on a fixed Hybrid Worker in Azure Automation
Easy methods to begin a runbook on a hard and fast Hybrid Employee in Azure Automation

Within the tab on the precise you see the Hybrid Staff below Consumer Hybrid Employee Teams.

These are the Hybrid Staff that you may run a runbook on.

How to run a PowerShell script on an assigned Hybrid Worker in a Hybrid Worker Group in Azure Automation
Easy methods to run a PowerShell script on an assigned Hybrid Employee in a Hybrid Employee Group in Azure Automation

So the parameter expects the Group Identify and never the Hybrid Employee itself.
My group title is ‘Check‘.

So the cmdlet now seems like this:

. .Begin-SpecificHybridWorker.ps1
Begin-SpecificHybridWorker -Runbook 'Runbook1' -HybridWorkerGroup 'Check'

HybridWorker

This parameter just isn’t obligatory! Bizarre eh? Nicely, not likely.


For while you do use the parameter

Keep in mind that should you enter a incorrect title you’ll get an infinite loop. So be sure that the title is right and that when the server is phased out, you additionally change it manually.

The title is similar because the title you get again from $env:COMPUTERNAME.
If we took my laptop computer for example, it could appear to be this:

$env:COMPUTERNAME

DESKTOP-1SDR953

So the cmdlet could be:

. .Begin-SpecificHybridWorker.ps1
Begin-SpecificHybridWorker -Runbook 'Runbook1' -HybridWorkerGroup 'Check' -HybridWorker 'DESKTOP-1SDR953'

For when you don’t use the parameter

If you don’t enter a reputation, the operate merely grabs the primary Hybrid Employee within the Hybrid Employee Group.

Should you don’t use the parameter HybridWorker, the operate does require some extra functionalities from Azure Automation.
We then want an additional operate, allow managed id and three variables in Azure Automation.


New-ManagedIdentityAccessToken operate

We’d like the New-ManagedIdentityAccessToken operate. This may also be discovered on Github.

Place it in Azure Automation in the identical means because the Begin-SpecificHybridWorker operate.

You don’t must dot supply it. That is finished robotically by the operate itself.


Allow Managed Identification

We have to allow Managed Identification in Azure Automation and provides it contributor permissions for itself.
Take a look at the screenshot beneath or use these two tutorials to do that:

How to start a Runbook on specific Hybrid Worker Azure Automation
Easy methods to begin a Runbook on particular Hybrid Employee Azure Automation

New Azure Automation variables

We additionally want 3 new Azure Automation variables.
All of them are strings.

  • AzureSubscription
    That is your AzureSubscriptionId.
  • ResourceGroupName
    The ResourceGroupName that comprises the AutomationAccount.
  • AzureAutomationAccount
    That is the AutomationAccountName

You may comply with the Microsoft Docs so as to add variables.

How to start a Runbook on specific Hybrid Worker Azure Automation
Easy methods to begin a Runbook on particular Hybrid Employee Azure Automation

StartSleep

To make a runbook begin on one other Hybrid Employee, I take advantage of the Begin-Sleep cmdlet.

In any other case I’m afraid the precise Hybrid Employee received’t be chosen as a result of the Runbook goes backwards and forwards between Hybrid Employee 1 and a pair of.

The default worth is 30 seconds. While you’ve bought greater than 2 Hybrid Staff I’d up this to not less than 60 seconds.

By customizing StartSleep the cmdlet could be:

. .Begin-SpecificHybridWorker.ps1
Begin-SpecificHybridWorker -Runbook 'Runbook1' -HybridWorkerGroup 'Check' -HybridWorker 'DESKTOP-1SDR953' -StartSleep 60

After the timer, the operate stops the runbook with the assertion Exit.


An actual instance of Begin-SpecificHybridWorker

Within the screenshots beneath you possibly can see that the runbooks begins the runbook once more and goes into sleep mode for 60 seconds.

 How to run a PowerShell script on an assigned Hybrid Worker in a Hybrid Worker Group in Azure Automation
Easy methods to run a PowerShell script on an assigned Hybrid Employee in a Hybrid Employee Group in Azure Automation

After 7 tries the eighth attempt was on the proper Hybrid Employee.

How to run a PowerShell script on an assigned Hybrid Worker in a Hybrid Worker Group in Azure Automation
Easy methods to run a PowerShell script on an assigned Hybrid Employee in a Hybrid Employee Group in Azure Automation

And with the tip consequence:

How to start a runbook on a fixed Hybrid Worker in Azure Automation
Easy methods to begin a runbook on a hard and fast Hybrid Employee in Azure Automation

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments