Login-AzureRmAccount无法使用PSCredential登录到Azure [英] Login-AzureRmAccount can't login to Azure using PSCredential
问题描述
我正在尝试从脚本非交互地登录到我的Azure帐户. 我只是不知道为什么它会失败:
I'm trying to login to my Azure account non-interactively from a script. I just don't know why it fails:
$secpasswd = ConvertTo-SecureString "P@$$W0rd" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("script1234@outlook.com", $secpasswd)
Login-AzureRmAccount -Credential $cred
这是我得到的错误:
Login-AzureRmAccount : Sequence contains no elements
有人可以帮我吗?
谢谢
推荐答案
Atf的答案很重要,但是,这不仅是问题.我们无法使用Hotmail或Outlook帐户直接以非交互方式直接登录.您必须使用您的帐户域登录.
Atf's answer has a point but however, this is not only the issue. We cannot directly sign in non-interactively using Hotmail or Outlook account. You must use domain of your account to sign in.
请参阅服务器故障中发布的类似问题:https://serverfault.com/questions/746557/add-azureaccount-unknown-user-type-unknown-user-type-on-azure-automation/746673
See a similar issue posted in server fault : https://serverfault.com/questions/746557/add-azureaccount-unknown-user-type-unknown-user-type-on-azure-automation/746673
它提到:
确保凭据资产名称(不是用户名)是一个简单的字符串. 还要确保凭据资产用户名是有效的OrgID用户 (例如:abc@fdgdf.onmicrosoft.com),而不是Microsoft/Live帐户 (joe@gmail.com).
Make sure the credential asset name (not username) is a simple string. Also make sure the credential asset username is a valid OrgID user (ex: abc@fdgdf.onmicrosoft.com), not a Microsoft / Live account (joe@gmail.com).
这篇关于Login-AzureRmAccount无法使用PSCredential登录到Azure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!