Azure Powershell Select-AzureSubscription with subscription id

AhmetB - Google picture AhmetB - Google · Jan 10, 2014 · Viewed 16.9k times · Source

I am using Powershell Azure cmdlets to do some operation on each subscription I have.

However, all my subscriptions have the same name. So if I do an operation like:

$subs | ForEach-Object {
    Select-AzureSubscription -Current -SubscriptionName $_.SubscriptionName
    $services = Get-AzureService
    Write-Output "$($services .Length) services under $($_.SubscriptionId) subscription"
}

it always works for the same subscription because the subscriptions only differ in subscription ID.

And the Select-AzureSubscription does not have a -SubscriptionId parameter.

Any ideas how can I find a workaround?

Answer

Rick Glos picture Rick Glos · Nov 16, 2015

Not sure if this was added later, but as of Nov 2015 you can use -SubscriptionId

Write-Host "Selecting Azure subscription using id"
Select-AzureSubscription -SubscriptionId $subscriptionId