Created
May 5, 2020 18:50
-
-
Save ehrnst/9e52d228e1851fd6490c7cc39be5be9b to your computer and use it in GitHub Desktop.
Multiple Azure users/context in PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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