Connect-AzAccount 无提示

Jos*_*eph 3 powershell azure azure-powershell

我正在尝试使用以下方式登录 Azure 门户

Connect-AzAccount
Run Code Online (Sandbox Code Playgroud)

此代码要求我输入我不想要的提示,我们可以使用一些简单的配置脚本自动登录吗?

Joe*_*Cai 6

正如Joy所说,您可以通过凭据使用用户帐户登录,但不会出现任何提示,请确保您的帐户未启用MFA。

$User = "xxx@xxxx.onmicrosoft.com"
$PWord = ConvertTo-SecureString -String "<Password>" -AsPlainText -Force
$tenant = "<tenant id>"
$subscription = "<subscription id>"
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User,$PWord
Connect-AzAccount -Credential $Credential -Tenant $tenant -Subscription $subscription
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

有关更多详细信息,您可以参考此SO 线程