I'm working on a script that involves jumping between two different user accounts in two different Azure tenants. With the Az
powershell module, I can set different auth contexts using:
Connect-AzAccount -ContextName "FirstContext" # interactive auth prompt 1
Connect-AzAccount -ContextName "SecondContext" # interactive auth prompt 2
then jump between them without any additional interactive prompts like this:
Select-AzContext -Name "FirstContext"
# do stuff within the first context
Select-AzContext -Name "SecondContext"
# do stuff within the second context
I need to do something similar (jumping back and forth between auth contexts in the same script) using cmdlets in the AzureAD
powershell module now... Does anyone know this may be able to be achieved? Both auth contexts require interactive MFA, which Get-Credential
doesn't seem to support.
Thanks!
$contextOne = Connect-AzAccount -ContextName "FirstContext"
? is there a reason why you are avoiding fixing up the accounts to follow least priviledge? – lloydAzureAD
module. I already can for theAz
module, but they're different modules, so I can't take the auth contexts fromAz
and pass them toAzureAD
. I'm happy to front-load MFA auth as much as necessary (once per module, per context, so 4x), but I'm looking to avoid re-MFAing within the same PS window when I want to switch between them. – Benjin