【问题标题】:Add-AzureRmAccount : Sequence contains no element (Not working for Gmail accounts too)Add-AzureRmAccount :序列不包含任何元素(也不适用于 Gmail 帐户)
【发布时间】:2017-08-09 20:57:56
【问题描述】:

我使用我的个人电子邮件 ID(Gmail ID)创建了一个“免费试用”帐户。我收到了错误:

Add-AzureRmAccount : 序列不包含任何元素 At line:1 char:1 + 添加-AzureRmAccount -Credential $cred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Add-AzureRmAccount], AadAuthenticationFailedException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.AddAzureRMAccountCommand

我运行的代码是

$username = "abc@gmail.com"
$password = "something"

$secpass = $password | ConvertTo-SecureString -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secpass

Add-AzureRmAccount -Credential $cred

是否有某些类型的帐户/订阅可以像这样登录?

【问题讨论】:

    标签: powershell azure azure-web-app-service azure-powershell


    【解决方案1】:

    Windows Live ID 凭据不能用于非交互式登录。此错误消息被描述为 this issue 的一部分,因为它需要改进而被提出。

    我认为您需要使用 Login-AzureRmAccount 以交互方式登录或创建服务主体以进行登录,根据本指南:https://docs.microsoft.com/en-us/powershell/azure/authenticate-azureps?view=azurermps-4.2.0

    使用服务主体登录

    服务主体为您提供了一种创建非交互式的方法 可用于操纵资源的帐户。服务主体 就像您可以使用 Azure Active 应用规则的用户帐户 目录。通过授予服务所需的最低权限 委托人,您可以确保您的自动化脚本更加完善 安全。

    1. 如果您还没有服务主体,create one

    2. 使用服务主体登录:

      Login-AzureRmAccount -ServicePrincipal -ApplicationId  "http://my-app" -Credential $pscredential -TenantId $tenantid
      

    【讨论】:

    • 感谢马克的快速回复!澄清一下,使用 gmail 帐户算作使用 Windows Live ID 凭据?
    • 是的,您可以使用任何电子邮件地址来创建 Windows Live ID afaik。
    • 如果您也能阐明允许非交互式登录的帐户类型以及我如何创建一个帐户,那就太好了。
    • 看似组织帐户(例如来自自定义域的工作或学校帐户)或服务主体(如上述答案中所述)。
    猜你喜欢
    • 2017-05-27
    • 2015-09-04
    • 2015-02-19
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    相关资源
    最近更新 更多