Set-AzContext: Please provide a valid tenant or a valid subscription

Set-AzContext: Please provide a valid tenant or a valid subscription.

I am trying to swap over to a different subscription within my Azure Account. The subscription is correct and the command itself seems to be correct but I am getting the error in the screenshot. Any suggestions..?

3

3 Answers

I avoid issues like that by listing all of your subscriptions you have access to, filter those for the one you want, and set that as your active context.

Get-AzContext -ListAvailable | Where{$_.Name -match 'MySub1'} | Set-AzContext 

You just need to fill in the name of the subscription or something. You can also run Get-AzContext -ListAvailable to see what subscriptions are available to you.

Make sure you logged in with the correct AAD tenant which the subscription locates in, just pass the tenant id to the command.

Set-AzContext -Subscription <subscription-id> -Tenant <tenant-id> 

After receiving this error I ran

Login-AzureRmAccount 

Logged in to the login screen that appeared and it started working

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobXFpaGqDd3yOrJytZZGvsLC6056vrWWgobKiv8Rmp6unpp6xpnnAZq2apJmZerWxzZqlrWWfp3qiedWao6KcXajCo7%2FCq6CprJmkuw%3D%3D