We have a command to get all the subscriptions - Get-AzSubscription | Set-Azcontext and set for that to work with multiple subscriptions.
How do we fetch a specific subscription from Get-AzSubscription and pass that for Set-Azcontext?
In order to do that I have tried below:
$subscription = Get-AzSubscription -TenantId "tenant id" | where-object{$_.Name -like 'required name*'}
$subscription | Set-AzContext
Is there any better way to do the same?
There is nothing wrong with your method as long as:
... -or ... -or ... clauses which is messy.If however:
Then you could do this:
$subs = @('Sub 1','Live Sub','2 Test','Deb')
$subs | get-azsubscription -SubscriptionName {$_} | set-azcontext