Search code examples
powershellazureazure-powershell

Azure PowerShell - Selecting Subscription


I need to select my Azure Subscription in Azure PowerShell.

I copy/paste the Subscription ID (to ensure no typos) from the Azure Management Portal, it's a hex-string:

enter image description here

When I run:

Select-AzureSubscription -SubscriptionId '0300...'

I get an error message:

Select-AzureSubscription : The subscription id 0300... doesn't exist.

I know my subscription ID is correctly copied from the settings in Azure Management Portal, I even did a BeyondCompare to make sure.

I'm wondering about security... am I missing something? Do I need to somehow provide my Azure credentials? It wouldn't make sense to just allow anyone to select any Azure subscription, unless the Subscription ID is supposed to be super-secret, like an SSN.


Solution

  • You need to log on to your Azure account first:

    To start working with the Azure Service Management cmdlets, first log on to your Azure account. To log on to your account, run the following command:

    Add-AzureAccount

    After logging into Azure, Azure PowerShell creates a context for the given session. That context contains the Azure PowerShell environment, account, tenant, and subscription that will be used for all cmdlets within that session. Now you are ready to use the modules below.