Powershell 添加AzureAccount-凭证不作为I';我希望

Powershell 添加AzureAccount-凭证不作为I';我希望,powershell,azure,Powershell,Azure,4天前(2014年8月4日),Azure Powershell的新版本在Add-AzureAccount cmdlet上包含了一个新的-Credential参数。我试图使用它,但我显然做错了什么。 首先,我将密码存储在一个文件中: read-host -assecurestring | convertfrom-securestring | out-file C:\temp\securestring.txt 然后尝试在AddAzureAccount中使用它 $password = cat C:\

4天前(2014年8月4日),Azure Powershell的新版本在Add-AzureAccount cmdlet上包含了一个新的-Credential参数。我试图使用它,但我显然做错了什么。 首先,我将密码存储在一个文件中:

read-host -assecurestring | convertfrom-securestring | out-file C:\temp\securestring.txt
然后尝试在AddAzureAccount中使用它

$password = cat C:\temp\securestring.txt | convertto-securestring
$username = "dhdom1\jamiet" #yes, this is the correct username
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$password
Add-AzureAccount -credential $mycred
添加AzureAccount的调用失败:

添加AzureAccount:user\u realm\u discovery\u失败:user realm discovery 失败:远程服务器返回错误:(404)未找到


我知道“dhdom1\jamiet”是正确的帐户。有人知道为什么会失败吗?TIA

您应该使用用于登录Azure门户的组织帐户。所以,它可能看起来像jamiet@yourorganizationalaccountname.com,或类似的东西

  • 打开azure powershell窗口
  • 键入AddAzureAccount,然后输入
  • 登录屏幕将弹出给他,然后输入此凭证outlook
  • 这样,此凭据将存储在此PowerShell窗口中,然后从此特定窗口运行所有其他脚本

  • 值得注意的是,-Credential参数目前不支持Microsoft帐户。它必须是一个组织帐户。如果你没有一个组织的Active Directory链接到你的Azure广告,你仍然可以创建一个Azure广告用户,将其设为联合管理员并使用它。默认情况下,每个Azure订阅都有一个Azure AD。我尝试使用我的组织帐户,但它给了我以下错误:添加AzureAccount:联邦服务返回错误:ID3242:无法验证或授权安全令牌。远程服务器返回错误:(500)内部服务器错误。有什么建议吗?尽管我一直在努力让这个程序在本地运行,但我很想知道你是如何将上面的内容应用到自动化runbook或function应用程序的?