使用新的 Azure 门户,我正在尝试添加一个将启动特定 VM 的 powershell runbook。这不是我的 PC 在 powershell 中运行的东西,而是作为 ARM 作业运行。我似乎找不到成功登录的方法。
如果在 powershell 中从我的桌面运行,我可以调用 Login-AzureRmAccount,它会在运行任何进一步的步骤之前启动一个登录对话框。从我在网上读到的内容看来,我需要做的是向我的自动化帐户添加一个凭据,检索它,然后调用相同的登录方法。我现在已经这样做了,但仍然无法登录。
Import-Module AzureRM.Compute
$AutomationCredentialAssetName = "automation"
$Cred = Get-AutomationPSCredential -Name $AutomationCredentialAssetName
Write-Output $Cred
Login-AzureRmAccount -Credential $Cred
Start-AzureRmVm -Name 'myvmname' -ResourceGroupName 'myresourcegroupname'
正在正确检索凭据(获取写入输出),但对 Login-AzureRmAccount 的调用失败,并显示:
Login-AzureRmAccount : unknown_user_type: Unknown User Type At line:10 char:1 + Login-AzureRmAccount -Credential $Cred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-AzureRmAccount], AadAuthenticationFailedException + FullyQualifiedErrorId : Microsoft.Azure.Common.Authentication.AadAuthenticationFailedException,Microsoft.Azure.Commands.Profile。添加AzureRMAccount命令
如果我不尝试先登录,我会收到一条消息,告诉我先调用 Login-AzureRmAccount。
如何从 Runbook 中进行身份验证,以便我可以运行自动化任务?我究竟做错了什么?