Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add-AzureRmAccount : Sequence contains no elements

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?

like image 586
Martin Erlic Avatar asked Jan 04 '23 18:01

Martin Erlic


1 Answers

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.

enter image description here

like image 198
Shui shengbao Avatar answered Jan 13 '23 09:01

Shui shengbao