Bla*_*Spy 2 powershell login azure runbook
使用新的Azure门户,我试图添加将启动特定VM的Powershell Runbook。这不是可以从我的PC在Powershell中运行的东西,而是作为ARM作业运行的。我似乎找不到成功登录的方法。
如果在Powershell中从桌面运行,我可以调用Login-AzureRmAccount,它将在运行任何其他步骤之前启动登录对话框。从我在网络上阅读的内容来看,我似乎需要做的是向我的自动化帐户添加凭据,对其进行检索,然后调用相同的Login方法。我现在已经完成了,但是仍然无法登录。
Import-Module AzureRM.Compute
$AutomationCredentialAssetName = "automation"
$Cred = Get-AutomationPSCredential -Name $AutomationCredentialAssetName
Write-Output $Cred
Login-AzureRmAccount -Credential $Cred
Start-AzureRmVm -Name 'myvmname' -ResourceGroupName 'myresourcegroupname'
Run Code Online (Sandbox Code Playgroud)
凭证已正确检索(将其写入输出),但对Login-AzureRmAccount的调用失败,并显示以下信息:
Login-AzureRmAccount:未知用户类型:未知用户类型在线:10 char:1 + Login-AzureRmAccount -Credential $ Cred + ~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ + AddAzureRMAccountCommand
如果我不尝试首先登录,则会收到一条消息,告诉我先致电Login-AzureRmAccount。
如何从运行手册中进行身份验证,以便可以运行自动化任务?我究竟做错了什么?
随后,我们发现自动化帐户在创建时创建了可用于登录的连接:
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7719 次 |
| 最近记录: |