Add-AzureRmAccount:序列不包含任何元素 [英] Add-AzureRmAccount : Sequence contains no elements

查看:95
本文介绍了Add-AzureRmAccount:序列不包含任何元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证脚本以通过PowerShell连接到Azure.

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

完整错误消息:

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无法使用以下方式登录到Azure PSCredential ,可能是特殊字符可能会导致错误,但我尝试将密码中的!转义为成功,但没有成功.还有什么可能导致此问题?

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?

推荐答案

这是AD的限制,您不能使用Microsoft Live帐户非交互地登录Azure.如果我的帐户不是Microsoft帐户,则可以登录Azure.

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.

这篇关于Add-AzureRmAccount:序列不包含任何元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆