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
In this article This document details how to use the PowerShell in Cloud Shell in the Azure portal. A Bash in Azure Cloud Shell Quickstart is also available.
Open the PowerShell console. Run Add-AzAccount or Connect-AzAccount or Login-AzAccount command. After the successful authentication validation, it will direct you to the PowerShell console. To see the profile file details, you can run the ls -lrt command to view the time and other details of JSON.
Description. The Set-AzContext cmdlet sets authentication information for cmdlets that you run in the current session. The context includes tenant, subscription, and environment information.
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.
If you are cycling through subscriptions in the same tenant and don't want to have to sign in with Connect-AzAccount
multiple times, the following worked for me to switch between subscriptions:
Remove-AzContext -InputObject (Get-AzContext) -Force | Out-Null;
$sub = Set-AzContext -Subscription $_.SubscriptionName;
Before adding the Remove-AzContext
statement I was seeing that Set-AzContext
was not actually switching the context to another subscription for some reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With