问题
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