azure - 有没有办法像使用 "AzureAD"模块一样在 "Az"powershell 模块中的身份验证上下文之间进行切换?

标签 azure powershell azure-active-directory azure-ad-powershell-v2

我正在编写一个脚本,该脚本涉及在两个不同 Azure 租户中的两个不同用户帐户之间跳转。借助 Az powershell 模块,我可以使用以下方法设置不同的身份验证上下文:

Connect-AzAccount -ContextName "FirstContext" # interactive auth prompt 1
Connect-AzAccount -ContextName "SecondContext" # interactive auth prompt 2

然后在它们之间跳转,无需任何额外的交互式提示,如下所示:

Select-AzContext -Name "FirstContext"
# do stuff within the first context
Select-AzContext -Name "SecondContext"
# do stuff within the second context

我现在需要使用 AzureAD powershell 模块中的 cmdlet 执行类似的操作(在同一脚本中的身份验证上下文之间来回跳转)...有谁知道这可以实现?两种身份验证上下文都需要交互式 MFA,而 Get-Credential 似乎不支持。

谢谢!

最佳答案

目前,Azure AD PowerShell 模块不支持选择上下文。

如果您只是想再次避免交互式 MFA,则可以使用服务主体登录,在执行所需操作后,断开连接并更改另一个服务主体。

Connect-AzureAD -TenantId "bb58915c-xxxxx5b97ed6c65" -ApplicationId "ec614bcd-d129-4ca4xxxxx19b07" -CertificateThumbprint "F1D9FE13xxxxx8B07D1666"

#do something you want

Disconnect-AzureAD

此外,这是Azure AD feedback ,您可以将其作为想法发布。

关于azure - 有没有办法像使用 "AzureAD"模块一样在 "Az"powershell 模块中的身份验证上下文之间进行切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56589989/

相关文章:

node.js - 无法使用 NodeJS/node-outlook 访问 Office 365

c# - 实体未添加到 Azure 表,但行键和分区键已正确添加

sql - 我们可以为逻辑应用 - SQL 数据库连接器定义超时吗

azure - Jersey 客户端 1.17 PUT 请求返回错误 411。请求必须分块或具有内容长度

python - 如何将数百万个文件移动到 Azure Blob 存储中同一容器中的另一个文件?

azure - 将员工 ID 添加到 azure AD 中的声明中,Add-AzureADServicePrincipalPolicy 给出服务主体 ID 不存在错误

windows - 如何在 Windows 上调试 "Could not add identity : agent refused operation"?

powershell - Powershell输出列宽度

powershell - 在 Foreach 之前加速测试连接

Azure 应用服务编辑器(摩纳哥)停止工作/无法访问 http 错误 500.1001