azure - 通过 powershell 使用 MFA 以编程方式对 AAD 进行身份验证

标签 azure powershell azure-active-directory multi-factor-authentication

我有一个 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 

引用 - Sign in with a service principal .

关于azure - 通过 powershell 使用 MFA 以编程方式对 AAD 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57772073/

相关文章:

azure - 有没有一种简单的方法可以查看已登录 Multi-Tenancy 应用程序的所有 Azure AD 租户?

azure - 授予帐户创建订阅的权限

azure - 如何在 ARM 模板中通过 ObjectID 获取 Azure AD 安全组名称?

git - Azure Databricks - 自动同步存储库文件

azure - 无法获取在 Azure 上运行的 VM 的 RDP

powershell - 使用 Powershell 安装 Sitecore 更新包

encoding - 使用 PowerShell 以 UTF-8 写入无 BOM 的文件

python - 使用 Azure Functions 的无服务器 Django

visual-studio - 本地 Azure 存储帐户 - 在哪里可以找到连接字符串

.net - Powershell命令Publish-AzWebApp未发布应用程序