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

Once, while executing the Set-AzContext Azure PowerShell cmdlet, I got the error “Please provide a valid tenant or a valid subscription.” while I was providing the correct subscription.

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

I was trying to execute the Set-AzContext PowerShell command recently, But I got this error.

Set-AzContext

The complete error message was as below

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

You can see the same in the screenshot below

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

Now, we will see How to fix the error “Please provide a valid tenant or a valid subscription.

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

To fix this error, you can follow the below steps.

  1. The first step is to close the current PowerShell session or use the Clear-AzContext PowerShell cmdlet.
  2. Now, you can use the below Azure PowerShell command in this way
Clear-AzContext
Connect-AzAccount -Tenant xxxxx -Subscription xxxxx

Or, you can use the below steps

1. Use the below Azure PowerShell cmdlet to get the list of contexts 

Get-AzContext -ListAvailable
please provide a valid tenant or a valid subscription

2. You can choose the context using the below Azure PowerShell cmdlet

Select-AzContext -Name #############
set-azcontext : please provide a valid tenant or a valid subscription

You can also set the Azure Subscription using the below PowerShell cmdlet. Either you can use the name or ID of the Azure Subscription.

PS C:\WINDOWS\system32> Set-AzContext -SubscriptionId "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
set-azcontext: please provide a valid tenant or a valid subscription.

Or you can also use the -SubscriptionName parameter with the Set-Azcontext Azure PowerShell cmdlet.

PS C:\WINDOWS\system32> Set-AzContext -SubscriptionName "Your Azure Subscription name"
set-azcontext please provide a valid tenant or a valid subscription

You can check out the Set-AzContext PowerShell command for more information.

Conclusion

In this way, you can fix the error Set-azcontext: Please provide a valid tenant or a valid subscription.