Selecting the right Subscription in PowerShell
When your organization has multiple Azure Subscriptions and you are entitled to work with them, selecting the correct subscription becomes an important thing to do.
Different approaches exist. I will have a look at the two most straight forward ones.
Using an argument to Connect-AzAccount
Connect-AzAccount holds specific attributes than can help you, namely SubscriptionName or SubscriptionId. If you know the Subscription name you want to connect to, issuing the following command directly connects to the correct subscription, after which you can start scripting:
Connect-AzAccount -SubscriptionName "Microsoft Partner Network"
To check to which subscription is linked, the command Get-AzContext can be issued.
Switching to another subscription in an active session
Switching to another Azure Subscription in an active session is also possible. This can be achieved by issuing the following command:
Set-AzContext -Subscription <subscription name> or <subscription id>
Useful PowerShell references