我尝试按照以下命令来获得无提示的更快登录体验,但每次我都会发现登录弹出窗口。我什至最初尝试使用证书,但由于证明不起作用,因此尝试使用租户 ID。有关如何无缝且更快地登录而不是交互的任何帮助或建议。
Login-AzureRmAccount -SubscriptionId 1238154XXXXfd-1c4121796e58 -TenantId 754XXXXXXXXXXX5d10d8XXX
Add-AzureRmAccount -Tenant "754XXXXXXXXXXX5d10d8XXX" -SubscriptionId "1238154XXXXfd-1c4121796e58"
Login-AzureRmAccount -TenantId 754XXXXXXXXXXX5d10d8XXX
或者,我是否必须始终通过交互式登录提示进行操作。请求指点并提前感谢您的考虑和时间。
最佳答案
您可以使用-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
$tenantID = "<the tenant id of your subscription>"
Add-AzureRmAccount -Credential $cred -TenantId $tenantID -ServicePrincipal
关于powershell - 如何不提示登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37249623/