4

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?

2
  • Your account is a Micrsoft account (such as *.outlook.com and *.hotmail.com) ? Jan 12, 2017 at 8:36
  • Yes it is a Microsoft account. Jan 12, 2017 at 8:36

1 Answer 1

9

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.