I am using the code below to create Hybrid worker in a secondary (DR) resource group and add it to an hybridworker group in an automation account in the primary resource group however it fails with the error
$rgDRname = 'rgjt4061rbdr'
$rgname = 'rgjt4061rb'
$aaname = 'aajt4061rb'
$hybridWorkerGroupName = 'hwrvmjt4061rbDNS1'
# Get the Hybrid Worker Group
$hybridWorkerGroup = Get-AzAutomationHybridWorkerGroup -ResourceGroupName $rgname - AutomationAccountName $aaname -Name $hybridWorkerGroupName
$vmDNS1resource = Get-AzVM -ResourceGroupName $rgDRname | Where-Object { $_.Name -like "vm*DNS1" }
[string]$vmDNS1resourceid = $vmDNS1resource.Id
# Create a new Hybrid Worker configuration
$hybridWorkerConfiguration = @{
ResourceGroupName = $rgname
AutomationAccountName = $aaname
VmResourceId = $vmDNS1resourceid
HybridRunbookWorkerGroupName = $hybridWorkerGroupName
Name = $vmDNS1resource.Name
}
# Add the new Hybrid Worker to the group
New-AzAutomationHybridRunbookWorker @hybridWorkerConfiguration
I got the error below
This is the error i have New-AzAutomationHybridRunbookWorker : The hybrid runbook worker id 'vmjt4061rbDNS1' is not in proper GUID format.
At line:1 char:1
+ New-AzAutomationHybridRunbookWorker @hybridWorkerConfiguration | gm
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzAutomationHybridRunbookWorker], ErrorResponseException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.NewAzureAutomationHybridRunbookWorker
Powershell Command but fails ..
If there is a way I can use Microsoft graph instead. that would be great.
You need to pass the GUID value for -Name
property as mentioned in this documentation on how to create and manage the hybrid worker.
I have modified the above shared PowerShell script and using the below I am able to deploy the Hybrid Runbook worker without any issues.
$rgDRname = 'rgjt4061rbdr'
$rgname = 'rgjt4061rb'
$aaname = 'aajt4061rb'
$hybridWorkerGroupName = 'hwrvmjt4061rbDNS1'
$workerName= New-Guid
$vmDNS1resource = Get-AzVM -ResourceGroupName $rgDRname | Where-Object { $_.Name -like "vm*DNS1" }
$vmDNS1resourceid = $vmDNS1resource.Id
# Create a new Hybrid Worker configuration
$hybridWorkerConfiguration = @{
ResourceGroupName = $rgname
AutomationAccountName = $aaname
VmResourceId = $vmDNS1resourceid
HybridRunbookWorkerGroupName = $hybridWorkerGroupName
Name = $workerName
}
# Add the new Hybrid Worker to the group
New-AzAutomationHybridRunbookWorker @hybridWorkerConfiguration