Display enabled Azure subscriptions


Sometimes, the most useful things are also the simplest.

If, like me, you administer an Azure tenant with a large number of subscriptions, some of which are cancelled (disabled), you’ll appreciate this one (OK, two) liner:

Function Get-ActiveAzSubscriptions { Get-AzSubscription | Where-Object -Property State -eq "Enabled" }

Set-Alias -Name activesubs -Value Get-ActiveAzSubscriptions

I put this PowerShell function and alias in $PROFILE. It’s a convenient way to produce a list of active (“enabled”) Azure subscriptions. I can then quickly copy the subscription GUID into a Select-AzSubscription -SubscriptionId cmdlet. Just enter activesubs in the pwsh console (assuming you’ve previously logged in with Connect-AzAccount.

If you’re running the preview of PowerShell 7, you can even pipe the output to Out-GridView. For example: activesubs | ogv. The output looks really nice that way.

Nothing fancy, but pretty useful for me. I hope you find it useful, too.


Posted

in

, ,

by

Comments

2 responses to “Display enabled Azure subscriptions”

  1. Peter Avatar
    Peter

    Do you happen to know what the “alias” means? Microsoft has the worst documentation — I can’t find anywhere that they actually tell us what an alias is! I’m trying to figure out if “alias” is just another name for “subscription” (which is how I’ve seen it used), or if it could be used to set another name to refer to a subscription (e.g. the normal use of alias). Thanks!

    1. Alex Neihaus Avatar
      Alex Neihaus

      Check the help for Set-Alias with Get-Help Set-Alias -Online.

      In this case, I am setting the alias activesubs to refer to the the much longer function name that produces the list of active Azure subscriptions for the current context.

Leave a Reply

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