如何阻止 'az login' 更改我的默认订阅?

How to stop 'az login' from changing my default subscription?

我尝试使用以下命令访问组织中的特定订阅:

az login --subscription ID

有效,az account list 告诉我我将此子更改为默认值:

{
    "cloudName": "AzureCloud",
    "homeTenantId": "ID",
    "id": "ID",
    "isDefault": true,
    "managedByTenants": [],
    "name": "Development and Test",
    "state": "Enabled",
    "tenantId": "ID",
    "user": {
      "name": "pawel@organization.com",
      "type": "user"
    }

但在使用 az login 后,它让我返回到此帐户的不同订阅:

  {
    "cloudName": "AzureCloud",
    "homeTenantId": "ID",
    "id": "ID",
    "isDefault": true,
    "managedByTenants": [],
    "name": "Visual Studio Professional Subscription",
    "state": "Enabled",
    "tenantId": "ID",
    "user": {
      "name": "pawel@organization.com",
      "type": "user"
    }
  }

两者都在同一个帐户上。如何在第一次订阅时强制登录?

PowerShell 7 导致此问题,经过多次重试,同事让我尝试 Windows PowerShell(旧版本) 效果非常好。

您可以使用以下 PowerShell 命令将特定订阅标记为来自 remote PowerShell

的默认订阅
 Set-AzContext
   [-Context] <PSAzureContext>
   [-ExtendedProperty <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
   [-Name <String>]
   [-Force]
   [-Scope <ContextModificationScope>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]