Select an Azure subscription easily

Recently, I posted a quickie for creating a function to display enabled Azure subscriptions using Get-AzSubscription and suggested that you might want to use Out-GridView to display the results.

What I should’ve also shown is that you can use the power of the PowerShell pipeline with OGV to actually make it easy to select the active Azure subscription you want.

Here’s a slightly expanded version of the previous post’s code:

Function Get-ActiveAzSubscriptions { Get-AzSubscription | Where-Object -Property State -eq "Enabled" }
Set-Alias -Name activesubs -Value Get-ActiveAzSubscriptions
Function selectsub {activesubs | Out-GridView -PassThru | Select-AzSubscription}

Putting this in your $PROFILE produces output that looks like this. Client specific data has been blurred, but you get the idea. All you have to do is select the subscription you want, click Export and voila, you’ve switched to an enabled subscription.

Out-GridView in PowerShell 7
Out-GridView with -PassThru in PowerShell 7 (click to enlarge)

It’s great that Out-GridView has returned in PowerShell 7. Combined with the -PassThru parameter, it’s always been useful in Windows and now we have it on all PowerShell platforms.


Posted

in

, , ,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *