我有一个 PowerShell 脚本,可使用用户凭据通过命令 Connect-AzAccount 登录 Azure 订阅。
代码如下:
$userPassword='password'
$userName="username"
$tenantId="########-####-####-####-############"
$subscriptionId="########-####-####-####-############"
$azureSecpassword = $userPassword | ConvertTo-SecureString -asPlainText -Force
$azureCredential = New-Object System.Management.Automation.PSCredential($userName, $azureSecpassword)
Connect-AzAccount -Credential $azureCredential -Tenant $tenantId -SubscriptionId $subscriptionId
上面的代码无需任何用户交互即可运行。
几天前,客户为用户启用了多重身份验证。 如何通过多重身份验证保持完全自动化的登录过程(无需用户交互)?
最诚挚的问候。
最佳答案
这是一个常见问题。不幸的是,答案是否定的。如果帐户启用了 MFA,您只需以交互方式登录即可。
在这种情况下,我们一般选择使用服务主体以非交互方式登录。
$azureAplicationId ="Azure AD Application Id"
$azureTenantId= "Your Tenant Id"
$azurePassword = ConvertTo-SecureString "client secret" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
关于azure - 通过 powershell 使用 MFA 以编程方式对 AAD 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57772073/