Search code examples
azurepowershellazure-powershellazure-cloud-shell

Set-AzContext works in Azure Cloud Shell but doesn't in Azure PowerShell


When i execute following command

Clear-AzureProfile
Connect-AzAccount -TenantID xxxxxxxxxxxxxxxxxxx
Set-AzContext -SubscriptionId xxxxxxxxxxxxxxxxxxx

in Azure PowerShell i get this error.

Set-AzContext : Please provide a valid tenant or a valid subscription.
At line:6 char:1
+ Set-AzContext -SubscriptionId xxxxxxxxxxxxxxxxxxx

and if i run the same command in Azure Cloud Shell it works

Name        Account         SubscriptionName    Environment    TenantId         
xxxx        xxxxxxx         xxxx                 xxxx             xxxx

I switched from free-trial to pay-as-you-go subscription and using credentials for pay-as-you-go in both environment but it doesn't work. can anyone help


Solution

  • Close your powershell and open a new one, or use Clear-AzContext, not Clear-AzureProfile. Then use Connect-AzAccount -Tenant xxxxx -Subscription xxxxx, it should work.