Find All agent-based Hybrid Runbook Workers

In case you are not away the Microsoft Monitoring Agent (MMA) will be retired on 31 August 2024. Prior to this date you will need to migrate all your agent-based hybrid workers to the extension-based worker. Microsoft has provided plenty of guidance on migrating the existing agent-based hybrid workers to extension-based hybrid workers. However, it may be difficult to keep track of all the hybrid workers in your environment and which ones have been migrated.

I put together the following script that will gather all the hybrid workers in your environment and let you know which ones are still agent-based. Just connect to Azure using the Connect-AzAccount and run this script below.

# Run Connect-AzAccount before running this script
Function Get-SubscriptionHybridRunbookWorkers{
    [CmdletBinding()]
    param(
        $SubscriptionId
    )
    # Set context to the subscription
    if($(Get-AzContext).Subscription.SubscriptionId -ne $SubscriptionId){
        Set-AzContext -SubscriptionId $SubscriptionId -ErrorAction Stop | Out-Null
    }
    Write-Verbose "Connected to $($(Get-AzContext).Subscription.Name)"

    # Get all of the automation accounts
    $AllAutomationAccounts = Get-AzAutomationAccount

    foreach($acct in $AllAutomationAccounts){
        Write-Verbose " - Account: $($acct.AutomationAccountName)"
        $autoAcct = @{
            AutomationAccountName = $acct.AutomationAccountName 
            ResourceGroupName = $acct.ResourceGroupName
        }
        # Get all the Hybrid Runbook Worker Groups
        $HybridRunbookWorkerGroups = Get-AzAutomationHybridRunbookWorkerGroup @autoAcct
        foreach($hrwg in $HybridRunbookWorkerGroups){
            # Output all the individual Hybrid Runbook Workers
            Get-AzAutomationHybridRunbookWorker @autoAcct -HybridRunbookWorkerGroupName $hrwg.Name | Select-Object WorkerType, WorkerName, 
                @{l='HybridRunbookWorkerGroupName';e={$hrwg.Name}}, @{l='GroupType';e={$hrwg.GroupType}}, @{l='SubscriptionId';e={$SubscriptionId}},
                @{l='AutomationAccountName';e={$acct.AutomationAccountName}}, @{l='ResourceGroupName';e={$acct.ResourceGroupName}}
        }
    }
}

# Get all enabled Azure subscriptions
$AllSubscriptions = Get-AzSubscription | Where-Object{ $_.State -eq 'Enabled' } | Select-Object Name, Id -Unique

$AllHybridRunbookWorkers = foreach($sub in $AllSubscriptions){
    Get-SubscriptionHybridRunbookWorkers -SubscriptionId $sub.Id
}

# Output all v1 hybrid workers aka the agent-based ones that need to be migrated
$AllHybridRunbookWorkers | Where-Object{ $_.WorkerType -eq 'HybridV1' }

Once the script is complete, it will output any hybrid workers that still have the worker type of HybridV1. This indicates that it is an agent-based worker and will need to be migrated.

WorkerType                   : HybridV1
WorkerName                   : MyOnPremSrv.contoso.com
HybridRunbookWorkerGroupName : HybridGroup01
GroupType                    : User
SubscriptionId               : d02f6dda-71fd-45b6-a0c0-4a9510dcb33e
AutomationAccountName        : MyAutomationAccount
ResourceGroupName            : TheResourceGroup

Any hybrid workers with the Group Type of User are members of a hybrid worker group. You can follow Microsoft’s guidance for migrating the existing agent-based hybrid workers to extension-based hybrid workers.

The Group Type of System indicates the machine is registered with the Automation Update Management. For these follow Microsoft’s guidance to move virtual machines from Automation Update Management to Azure Update Manager.