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.
I was trying to execute the Set-AzContext PowerShell command recently, But I got this error.
Set-AzContextThe 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

Now, we will see How to fix the error “Please provide a valid tenant or a valid subscription.“
Solution
To fix this error, you can follow the below steps.
- The first step is to close the current PowerShell session or 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 xxxxxOr, you can use the below steps
1. Use the below Azure PowerShell cmdlet to get the list of contexts
Get-AzContext -ListAvailable
2. 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.

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
