Azure Runbook:要使用哪些凭据?

时间:2017-05-01 03:56:29

标签: powershell azure credentials azure-powershell runbook

我正在尝试创建一个Runbook来重新启动我的网络应用。我是新手,所以我在自动化刀片中创建了一个凭证,但我不知道用户名/密码应该是什么?我的azure登录帐户是否相同? 试过这个,显然当我测试Runbook时出现了这个错误:

Add-AzureAccount : unknown_user_type: Unknown User Type
At RestartJob:13 char:13
+ + CategoryInfo          : CloseError: (:) [Add-AzureAccount], 

AadAuthenticationFailedException
   + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount

一直试图在msdn上解决这个问题..任何帮助?

1 个答案:

答案 0 :(得分:1)

根据你的描述,我在我的实验室进行测试。这些笨拙的cmdlet适合我。

$ConnectionAssetName = "shuitest"

# Get the connection
$connection = Get-AutomationConnection -Name $connectionAssetName        

# Authenticate to Azure with certificate
Write-Verbose "Get connection asset: $ConnectionAssetName" -Verbose
$Conn = Get-AutomationConnection -Name $ConnectionAssetName
if ($Conn -eq $null)
{
    throw "Could not retrieve connection asset: $ConnectionAssetName. Assure that this asset exists in the Automation account."
}

$CertificateAssetName = $Conn.CertificateAssetName
Write-Verbose "Getting the certificate: $CertificateAssetName" -Verbose
$AzureCert = Get-AutomationCertificate -Name $CertificateAssetName
if ($AzureCert -eq $null)
{
    throw "Could not retrieve certificate asset: $CertificateAssetName. Assure that this asset exists in the Automation account."
}

Write-Verbose "Authenticating to Azure with certificate." -Verbose
Set-AzureSubscription -SubscriptionName $Conn.SubscriptionName -SubscriptionId $Conn.SubscriptionID -Certificate $AzureCert 
Select-AzureSubscription -SubscriptionId $Conn.SubscriptionID

在执行Runbook之前,您应该在Azure门户上创建AssetName和Certificate。

1. Azure自动化中的证书资产

请选择your runbook - > ASSETS - Certificateenter image description here

2.创建连接(AssetName)。请选择your runbook - > ASSETS - Connections。根据您的方案,您应该选择AzureClassicCertificate

enter image description here