I set up a visual studio project template that runs setup scripts to automatically register an application and create application insights for the app. The problem is the app registration uses the AzureAD module while the application insights (and the resource group creation if needed) use the Az modules, so I end up needing to do
Connect-AzAccount
Connect-AzureAD
Which prompts the user for their login twice. Is there a way to use the auth from one to authenticate the other?
I've seen similar questions suggesting using get-credential but since my org has multi factor auth that wont work.
Other suggestions were to use a service principal but I don't want to store anything specific in the template and want the auth tied to the user.
I know the Az module has functionality similar to the AzureAD (New-AzADApplication
) but there are a few things I can't figure out how to do. Specifically, set the applications permissions to sign in on Microsoft graph and set the application owner to the authenticated user. That is why i'm using the AzureAD module instead
If you want to use the same session to connect Azure and Azure AD in PowerShell, please refer to the following script
Connect-AzAccount
$context=Get-AzContext
Connect-AzureAD -TenantId $context.Tenant.TenantId -AccountId $context.Account.Id
Get-AzureADUser
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With