The more I work on Azure, the more I am having to switch between subscriptions. Now, this usually means copying and pasting the subscription ID every time. This is no good! So I decided to see if I can script a subscription selector and I did. It’s below!
The script basically gets you to login to your Azure subscription, then uses Get-AzureRmSubscription to output the subscriptions into an Out-GridView. You then select the subscription you would like to use and then click OK.
I have started to add this script to my bigger Azure scripts. No more Azure resources in the wrong subscription for me!
|$SubscriptionId = (Get-AzureRmSubscription | select Name, State, SubscriptionId, TenantId | Out-GridView -Title "Azure Subscription Selector" -PassThru).SubscriptionId|
|Get-AzureRmSubscription -SubscriptionId $SubscriptionId | Select-AzureRmSubscription|
I hope you found this article helpful. If you have any questions or comments please reach out.
I’m Richard Hooper aka Pixel Robots. I started this blog in 2016 for a couple reasons. The first reason was basically just a place for me to store my step by step guides, troubleshooting guides and just plain ideas about being a sysadmin. The second reason was to share what I have learned and found out with other people like me. Hopefully, you can find something useful on the site.