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.
Leave a Reply