Powershell Azure:术语 'Get-AutomationConnection' 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称

Powershell Azure : The term 'Get-AutomationConnection' is not recognized as the name of a cmdlet, function, script file, or operable program

我正在尝试连接到 Azure 运行 作为连接,作为执行数据库备份的 Powershell 脚本的一部分。

此脚本试图调用 Get-AutomationConnection

如屏幕截图所示,Get-Module 执行 return Azure / Azure.StorageAzureRM 显示。

我还应该导入什么模块才能正常工作?

如果你想连接到 Azure 运行 作为来自 Windows PowerShell 的连接,你应该使用 New-AzureRmAutomationConnection.

$ConnectionAssetName = "AzureRunAsConnection"
$ConnectionFieldValues = @{"ApplicationId" = $Application.ApplicationId; "TenantId" = $TenantID.TenantId; "CertificateThumbprint" = $Cert.Thumbprint; "SubscriptionId" = $SubscriptionId}
New-AzureRmAutomationConnection -ResourceGroupName $ResourceGroup -AutomationAccountName $AutomationAccountName -Name $ConnectionAssetName -ConnectionTypeName AzureServicePrincipal -ConnectionFieldValues $ConnectionFieldValues 

您可以使用该脚本创建连接资产,因为当您创建自动化帐户时,默认情况下它会自动包含几个全局模块以及连接类型 AzurServicePrincipal 以创建 Azure运行AsConnection 连接资产。

Get-AutomationConnection 在 Azure Runbook 内部运行。

请参考connection assets in Azure Automation

如果您想要与本地运行手册类似的功能,可以安装 AzureAutomationAuthoringToolkit。它会给你非常相似的功能。我有一个使用服务主体登录的脚本,无论它是 运行 内部部署还是在 Azure Runbook 中。它在 运行 内部部署时使用 AAATK 提供的资源,模拟运行手册。

我确实尝试过使用“Microsoft Monitoring agent”(Hybrid worker)附带的 Get-AutomationConnection 版本,但后来我读到它与 AzureAutomationAuthoringToolkit 附带的版本不同,详见“ GitHub readme 中的已知问题”。我无法让它工作,所以我恢复到 AAATK 的版本。