powershell - 如何不提示登录?

标签 powershell azure automation

我尝试按照以下命令来获得无提示的更快登录体验,但每次我都会发现登录弹出窗口。我什至最初尝试使用证书,但由于证明不起作用,因此尝试使用租户 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/

相关文章:

azure - 逻辑应用程序在 Microsoft Teams 中发帖

javascript - 每次我在 Firefox 中打开特定网站时如何执行 javascript?

python - Selenium 单击 instagram Python 上的所有关注按钮

powershell - Powershell:将“上次修改时间”与“特定日期”进行比较,并用正确的日期替换

azure - 如何在 Azure DevOps/GitHub 中设置 PR 验证?

powershell - 最大化窗口并使用Powershell将其置于最前面

azure - Power Bi Desktop 中的 Power BI Rest Api 数据集

Python Selenium(等待框架、元素查找)

powershell - 当它们位于不同节点时,为什么 PowerShell DSC 说我有重复的资源标识符?

powershell - 通过网络Powershell命令发现OS版本而不是Windows 10 1809