您可以使用-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實例中爲您的工作或學校定義。 –