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

前端 未结 3 865
难免孤独
难免孤独 2021-02-15 10:39

When i execute following command

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

3条回答
  •  一整个雨季
    2021-02-15 10:44

    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.

提交回复
热议问题