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.
Table of Contents
Set-AzContext : Please provide a valid tenant or a valid subscription.
Recently, I was trying to execute the Set-AzContext PowerShell command, 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 below screenshot

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.
- The first step is to close the current PowerShell session or you can also use the Clear-AzContext PowerShell cmdlet.
- 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
- Use the below Azure PowerShell cmdlet to get the list of contexts
Get-AzContext -ListAvailable

- You can choose the context using the below Azure PowerShell cmdlet
Select-AzContext -Name #############

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"

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"

You can check out the Set-AzContext PowerShell command for more information.
Conclusion
In this way you can able to fix the error Set-azcontext: Please provide a valid tenant or a valid subscription.