您可以使用-Credential
参数和DPAPI登录。
首先,运行以下PowerShell一次以存储您帐户的安全密码。
Read-Host "Enter Password" -AsSecureString | ConvertTo-SecureString `
-AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\Password.txt"
然后,您可以使用以下脚本来登录。
# The azure account here must not be a Live ID.
$username = "<your Azure account>"
$SecurePassword = Get-Content "C:\Password.txt" | ConvertTo-SecureString
$cred = new-object -typename System.Management.Automation.PSCredential `
-argumentlist $username, $SecurePassword
Login-AzureRmAccount -Credential $cred
另一种方式是使用服务负责人。首先,您应该按照the article创建服务负责人
然后,使用以下脚本进行登录。
$clientID = "<the client id of your AD Application>"
$key = "<the key of your AD Application>"
$SecurePassword = $key | ConvertTo-SecureString -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential `
-argumentlist $clientID, $SecurePassword
Add-AzureRmAccount -Credential $cred -Tenant "xxxx-xxxx-xxxx-xxxx" -ServicePrincipal
我想,我找到了原因。读完msdn后,我发现这部分=>这种非交互式登录方法只适用于工作或学校帐户。工作或学校帐户是由您的工作或学校管理的用户,并在Azure Active Directory实例中为您的工作或学校定义。 –