通过 PowerShell 创建 Azure 自动化连接 - 错误 'account was not found'

Creation of an Azure Automation Connection via PowerShell - error 'account was not found'

我是运行以下PowerShell代码:

Get-AzureRmAutomationAccount `
    -ResourceGroupName $AUTOMATION_ACCOUNT_RESOURCE_GROUP `
    -Name $AUTOMATION_ACCOUNT_NAME 

New-AzureRmAutomationConnection 
    -ResourceGroupName $AUTOMATION_ACCOUNT_RESOURCE_GROUP `
    -AutomationAccountName $AUTOMATION_ACCOUNT_NAME `
    -Name $ConnectionAssetName `
    -ConnectionTypeName AzureServicePrincipal `
    -ConnectionFieldValues $ConnectionFieldValues 

Get-AzureRmAutomationAccount 显示自动化帐户的详细信息,但 New-AzureRmAutomationConnection(尽管使用完全相同的参数值)抛出以下错误:

New-AzureRmAutomationConnection : The Automation account was not found.
At line:2 char:1
+ New-AzureRmAutomationConnection -ResourceGroupName $AUTOMATION_ACCOUN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureRmAutomationConnection], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.NewAzureAutomationConnection

感谢任何我可能遗漏的建议! :)

该错误具有误导性,您最有可能看到的错误与错误字段有关。 运行 用于查看值的调试的 cmdlet 是否失败。您必须向上滚动一点才能找到正文中的异常。

确保您拥有证书指​​纹、子 ID、租户和应用程序 ID。我刚刚测试了以下内容,它按预期工作。 (当然取代了我的价值观)。希望这对您有所帮助!

New-AzureRmAutomationConnection `
    -ResourceGroupName TestAzureAuto `
    -AutomationAccountName TestAzureAuto `
    -Name "MyAsset2" `
    -ConnectionTypeName AzureServicePrincipal `
    -ConnectionFieldValues @{"CertificateThumbprint"="0000000000000000000000000000000000000000";"SubscriptionID"="00000000-0000-0000-0000-000000000000";"ApplicationId" = "00000000-0000-0000-0000-000000000000"; "TenantId" = "00000000-0000-0000-0000-000000000000" }