Add-AzureRmAccount:Sequence不包含任何元素

时间:2017-01-12 08:23:19

标签: powershell azure azure-powershell

我尝试验证脚本以通过PowerShell连接到Azure。

$username = "asdfasdf"
$password = "asdfasdf"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
Add-AzureRmAccount -Credential $cred
Select-AzureRmSubscription -SubscriptionId asdfasdf

完整的错误消息:

Add-AzureRmAccount : Sequence contains no elements
At C:\Users\Martin\Documents\Tasks\Azure Script ARM API Syntax Conversion\Connect Azure V1.ps1:6 char:1
+ Add-AzureRmAccount -Credential $cred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Add-AzureRmAccount], AadAuthenticationFailedException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.AddAzureRMAccountCommand

我在这里看到Login-AzureRmAccount can't login to Azure using PSCredential,也许特殊字符可能会导致错误,但我尝试在密码中转义!但未成功。还有什么可能导致这个问题?

1 个答案:

答案 0 :(得分:9)

这是AD限制,您无法使用Microsoft Live帐户以非交互方式登录Azure。我在我的实验室中测试过,如果我的帐户是非Microsoft帐户,我可以登录Azure

enter image description here