6

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?

ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214

3 Answers3

9

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
Rick Glos
  • 2,466
  • 2
  • 29
  • 30
  • @Rick! I am executing powershel script to azure gov cloud that I downloaded from azure portal. I am getting this error - Select-AzureRmSubscription : Provided subscription 8888888408e8 does not exist – user557657 Jun 06 '17 at 13:20
4

If you are an account administrator for your account, you can change the name of your subscription. This way when you or anyone else who has access to the subscription downloads publishsettings, the name will be set the way you want.

http://rickrainey.com/windows-azure-how-tos/how-to-change-the-name-of-your-windows-azure-subscription/

Rick Rainey
  • 11,096
  • 4
  • 30
  • 48
1

Edit the publishsettings file, giving each subscription a different name. Then re-import. At that point, you'll be able to easily access each one uniquely by name.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • This did not work for me. `Import-AzurePublishSettingsFile` with just changing the name left the name with the original name when imported instead of the new one. – Rick Glos Nov 16 '15 at 20:37