powershell 如何在创建Hybridworker后在Azure中安装Hybridworker扩展?

kknvjkwl  于 12个月前  发布在  Shell
关注(0)|答案(1)|浏览(139)

我用下面的代码创建了hybridworker

$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

字符串
我试图安装混合工人扩展,但无法找出简单的方法来获得注册URL/设置部分排序。

$settings = @{
    RegistrationUrl = "https://your-automation-account.azure-automation.net/accounts/$automationAccountName"
}

Set-AzVMExtension -ResourceGroupName $resourceGroupName -VMName $vmName -Location "YourVMRegion" `
    -ExtensionName $extensionName -Publisher $publisher -ExtensionType $extensionName `
    -TypeHandlerVersion $version -Settings $settings -ProtectedSettings $protectedSettings `


请我需要如何使用Set-AzVMExtension的帮助,并获得注册URL -ForceRerun $true -Verbose

cyej8jka

cyej8jka1#

我使用下面的脚本创建了混合工人。

# Your existing code to create Hybrid Worker
$rgDRname = '<RgDRName>'
$rgname = '<RgName>'
$aaname = '<AutomationName>'
$hybridWorkerGroupName = '<hybridWorkerGroupName>'
$workerName = New-Guid

# Provide the full resource ID of your VM
$vmResourceId = '/subscriptions/158bxxxxxxx48f/resourceGroups/XXXXX/providers/Microsoft.Compute/virtualMachines/XXXXX-vm'

# Create a new Hybrid Worker configuration
$hybridWorkerConfiguration = @{
    ResourceGroupName = $rgname
    AutomationAccountName = $aaname
    VmResourceId = $vmResourceId
    HybridRunbookWorkerGroupName = $hybridWorkerGroupName
    Name = $workerName
}

# Add the new Hybrid Worker to the group
New-AzAutomationHybridRunbookWorker @hybridWorkerConfiguration

字符串
x1c 0d1x的数据
要安装 *Hybrid worker扩展 *,您可以使用以下修改后的脚本:

$settings = @{
    "AutomationAccountURL"  = "https://1a0426bb-69xxxxxxx.jrds.eus.azure-automation.net/automationAccounts/1a0426bbxxxxxx";
};

Set-AzVMExtension -ResourceGroupName <VMResourceGroupName> -Location <VMLocation> -VMName <VMName> -Name "HybridWorkerExtension" -Publisher "Microsoft.Azure.Automation.HybridWorker" -ExtensionType HybridWorkerForWindows -TypeHandlerVersion 1.1 -Settings $settings -EnableAutomaticUpgrade $true

  • 输出 *:
RequestId IsSuccessStatusCode StatusCode ReasonPhrase
--------- ------------------- ---------- ------------
                         True         OK


要获取**AutomationAccountURL**->在您的自动化->属性->使用自动化混合服务URL,如下所示



当我在门户中确认时,扩展成功安装,如下所示:


更新:

要获取**automationHybridServiceUrl,您可以使用REST API,如下所示:
创建
Azure AD应用程序**并授予API权限:



生成访问令牌

https://login.microsoftonline.com/TenantID/oauth2/v2.0/token

client_id:ClientID
client_secret:ClientSecret
scope:https://management.azure.com/.default
grant_type:client_credentials


x1c4d 1x的

使用以下查询获取Automation Hybrid服务URL:

https://management.azure.com/subscriptions/SubID/resourceGroups/RG/providers/Microsoft.Automation/automationAccounts/Automationaccname?api-version=2021-06-22&$expand=properties($select=automationHybridServiceUrl)


输出:

"state": "Ok",
"RegistrationUrl": "https://cdf826ae-f0a7-4fe3-b8a9-36f07XXXX.agentsvc.eus.azure-automation.net/accounts/cdf826ae-f0a7-4fe3-b8a9-36fXXX",
"encryption": {
"keySource": "Microsoft.Automation",
"identity": {
"userAssignedIdentity": null
}
},
"privateEndpointConnections": [],
"automationHybridServiceUrl": "https://cdf826ae-f0a7-fe3-b8a9-36f07XXXX.jrds.eus.azure-automation.net/automationAccounts/cdf826ae-f0a7-4fe3-b8a9-36f07XXX",
"RuntimeConfiguration": {
"powershell": {
"builtinModules": {
"Az": "8.0.0"
}

相关问题