MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.26k stars 21.43k forks source link

Impossible to switch to different subscription in cloud shell #33533

Closed artisticcheese closed 1 year ago

artisticcheese commented 5 years ago

Not sure when it stopped working but it's impossible to switch context in cloudshell to different subscription

PS Azure:\> Select-AzSubscription "NTT Data Subscription" -Verbose
VERBOSE: Switching targeted subscription in the context to 'NTT Data Subscription'

Name                                     Account                                         SubscriptionName                               Environment                                    TenantId
----                                     -------                                         ----------------                               -----------                                    --------
Mcafee MSDN (b55607ab-c703-4044-a526-72… MSI@50342                                       Mcafee MSDN                                    AzureCloud                                     c0de79f3-23e2-4f18-989e-d173e1d403d6

Azure:/
PS Azure:\> Get-AzSubscription

Name                  Id                                   TenantId                             State
----                  --                                   --------                             -----
Mcafee MSDN           b55607ab-c703-4044-a526-72bd701b0d48 c0de79f3-23e2-4f18-989e-d173e1d403d6 Enabled
NTT Data Subscription 8211cd03-4f97-4ee6-af42-38cad1387992 c0de79f3-23e2-4f18-989e-d173e1d403d6 Enabled

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

maertendMSFT commented 5 years ago

I cannot repro this. Are you still seeing this issue? What if the output of $env:ACC_VERSION in Cloud Shell?

artisticcheese commented 5 years ago

Yes, still seeing this requested output is below

PS Azure:\> $env:ACC_VERSION
master_20190614.1
Azure:/
PS Azure:\> Get-AzSubscription

Name                  Id                                   TenantId                             State
----                  --                                   --------                             -----
Mcafee MSDN           b55607ab-c703-4044-a526-72bd701b0d48 c0de79f3-23e2-4f18-989e-d173e1d403d6 Enabled
NTT Data Subscription 8211cd03-4f97-4ee6-af42-38cad1387992 c0de79f3-23e2-4f18-989e-d173e1d403d6 Enabled

Azure:/
PS Azure:\> Select-AzSubscription "NTT Data Subscription" -Verbose
VERBOSE: Switching targeted subscription in the context to 'NTT Data Subscription'

Name                                     Account                                         SubscriptionName                               Environment                                    TenantId
----                                     -------                                         ----------------                               -----------                                    --------
Mcafee MSDN (b55607ab-c703-4044-a526-72… MSI@50342                                       Mcafee MSDN                                    AzureCloud                                     c0de79f3-23e2-4f18-989e-d173e1d403d6
maertendMSFT commented 5 years ago

Can you supply the Id instead of the name?

artisticcheese commented 5 years ago

Does not work either

PS Azure:\> Select-AzSubscription -SubscriptionId 8211cd03-4f97-4ee6-af42-38cad1387992 -Verbose
VERBOSE: Switching targeted subscription in the context to '8211cd03-4f97-4ee6-af42-38cad1387992'

Name                                     Account                                         SubscriptionName                               Environment                                    TenantId
----                                     -------                                         ----------------                               -----------                                    --------
Mcafee MSDN (b55607ab-c703-4044-a526-72… MSI@50342                                       Mcafee MSDN                                    AzureCloud                                     c0de79f3-23e2-4f18-989e-d173e1d403d6
jasonpnnl commented 5 years ago

I am having the same issue. I found a workaround was to use Select-AzureRmContext instead as there were precreated contexts for each of my subscriptions.

jrudley commented 4 years ago

I'm having the same issue PS Azure:> $env:ACC_VERSION master_20191213.3

anderseide commented 4 years ago

Got some great tips from some fellow MVPs that I don't have the GitHub alias for. They deserve all credit for this one.

Following solved it for me

Clear-AzContext
# https://docs.microsoft.com/en-us/powershell/module/az.accounts/clear-azcontext?view=azps-3.3.0
# Remove all Azure credentials, account, and subscription information.

Connect-AzAccount
# https://docs.microsoft.com/en-us/powershell/module/az.accounts/connect-azaccount?view=azps-3.3.0
# Connect to Azure with an authenticated account for use with Azure Resource Manager cmdlet requests.

Set-AzContext and Select-AzSubscription should work again

leoruiz commented 4 years ago

This is happening to me too

$env:ACC_VERSION master_20200306.3

the-blesss commented 4 years ago

This has been happening for a while now. I don't think this should be desired behavior. It is causing working local PS code to fail in Cloud Shell, since you cannot automate changing context for multi subscription environments. Using the Clear-AzContext then Connect-AzAccount is a really clunky work-around.

$env:ACC_VERSION master_20200424.2

theBlueclouds commented 3 years ago

Connect-AzAccount also fails hence no way to switch subscription on cloud shell. https://github.com/Azure/azure-powershell/issues/13340

sdwheeler commented 1 year ago

label:"cloud-shell/svc"

sdwheeler commented 1 year ago

reassign:sdwheeler

sdwheeler commented 1 year ago

This problem no longer exists.

please-close