Azure Powershell Select-AzureSubscription with subscription id
Solution 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.
Solution 2
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
Solution 3
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.
ahmet alp balkan
I am a software engineer on Twitter compute infrastructure team. Previously I've worked at Google Cloud on Kubernetes, Cloud Run and Knative, and at Microsoft Azure on various parts of the Docker open source ecosystem. Find me on my: (blog | twitter | github)
Updated on June 26, 2022Comments
-
ahmet alp balkan almost 2 years
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?
-
user1600801 over 8 yearsThis 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. -
user557657 almost 7 years@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