powershell - 添加-AzureRmAccount : Sequence contains no elements

标签 powershell azure azure-powershell

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

$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 can't login to Azure using PSCredential也许特殊字符可能会导致错误,但我尝试转义密码中的一个 ! 但没有成功。还有什么可能导致此问题?

最佳答案

这是 AD 限制,您无法使用 Microsoft Live 帐户以非交互方式登录 Azure。 我在实验室测试过,如果我的帐户是非 Microsoft 帐户,我可以登录 Azure .

enter image description here

关于powershell - 添加-AzureRmAccount : Sequence contains no elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41608217/

相关文章:

c# - 从 System.Management.Automation 调用脚本时未设置 $PSScriptRoot

asp.net - 将本地数据库从 app_data 文件夹迁移到 SQL Azure

azure - 如何在复制数据映射中包含 blob 元数据

azure - 执行 Azure 函数 cmdlet Get-AzADAppCredential 的权限不足

powershell - 如何使用Powershell移动和重命名多个文件?

powershell - 将 txt 中的空行转换为 CSV 中的空行

arrays - 如何从 powershell 中的扩展类型数组中提取/匹配文件类型扩展

javascript - 如何设置队列输出的过期时间 - Azure function js

Azure Powershell 诊断设置

azure - 在 Azure ARM 模板中将变量与字符串连接起来