Add-AzureRmAccount : Sequence contains no elements

被刻印的时光 ゝ 提交于 2020-01-03 17:12:34

问题


I'm trying to validate a script to connect to Azure via PowerShell.

$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

Full error message:

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

I saw here Login-AzureRmAccount can't login to Azure using PSCredential that perhaps special characters may cause an error but I tried escaping the one ! in my password without success. What else could be causing this problem?


回答1:


This is an AD restriction, you cannot login non-interactively to Azure using a Microsoft Live account. I tested in my lab, if my account is non-Microsoft account, I could login to Azure.



来源:https://stackoverflow.com/questions/41608217/add-azurermaccount-sequence-contains-no-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!