Skip to content

Instantly share code, notes, and snippets.

@ehrnst
Created May 5, 2020 18:50
Show Gist options
  • Select an option

  • Save ehrnst/9e52d228e1851fd6490c7cc39be5be9b to your computer and use it in GitHub Desktop.

Select an option

Save ehrnst/9e52d228e1851fd6490c7cc39be5be9b to your computer and use it in GitHub Desktop.
Multiple Azure users/context in PowerShell
# Connect to Azure specifying a tenant
# If you want to connect to multiple tenants, you can connect multiple times.
Connect-AzAccount -tenantId customer1.onmicrosoft.com
# adding a new PowerShell Azure context
# setting a friendly name to allow for easy switching.
Set-AzContext -name "Subscription 1 in tenant 1" -SubscriptionId "31ffbc99-4cbf-43b2-8789-ba8d73171e70" -tenantid customer1.onmicrosoft.com
Set-AzContext -name "Subscription 2 in tenant 1" -SubscriptionId "b5c85827-0afd-49a0-8923-8fe35cfa8dd0" -tenantid customer1.onmicrosoft.com
# check the current context
Get-AzContext
# Get all contexts available
Get-AzContext -ListAvailable
#Switch between the contexts available
Select-AzContext 'Subscription 1 in tenant 1'
#Clear all contexts/log out
Clear-AzContext -force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment