azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Connect-AzAccount -MaxContextPopulation not working when called with existing contexts

Open jiasli opened this issue 4 years ago • 3 comments

Description

Connect-AzAccount -MaxContextPopulation not working when called with existing contexts.

Steps to reproduce

First delete ~/.azure.

> Connect-AzAccount
# Returned 1 item in total

> Get-AzContext -ListAvailable
# Returned 25 items in total

> Connect-AzAccount -MaxContextPopulation 100
# Returned 1 item in total

> Get-AzContext -ListAvailable
# Still returned 25 items in total

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

> Get-Module  -ListAvailable

    Directory: C:\Users\xxx\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     5.6.0                 Az                                  Core,Desk
Script     2.2.6                 Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzCo…

jiasli avatar Mar 09 '21 06:03 jiasli

Once user logged in, current powershell doesn't fetch tenants/subs again. So you need to call Disconnect-AzAccount first and then call Connect-AzAccount -MaxContextPopulation nnn

dingmeng-xue avatar Mar 11 '21 01:03 dingmeng-xue

We are considering this feature because it's not easy fix and it changes the default behavior of Connect-AzAccount

dingmeng-xue avatar Mar 11 '21 01:03 dingmeng-xue

Possibly related. I noticed Azure PowerShell doesn't get all subscriptions in the second tenant 72f988bf-86f1-41af-91ab-2d7cd011db47 which I pass to Connect-AzAccount. Tenant 72f988bf-86f1-41af-91ab-2d7cd011db47 contains several subscriptions, but only one is populated as a context.

> Connect-AzAccount -Tenant 54826b22-38d6-4fb2-bad9-b7b93a3e9c5a

Account              SubscriptionName TenantId                             Environment
-------              ---------------- --------                             -----------
[email protected] AzureSDKTest     54826b22-38d6-4fb2-bad9-b7b93a3e9c5a AzureCloud

> Connect-AzAccount -Tenant 72f988bf-86f1-41af-91ab-2d7cd011db47
WARNING: TenantId '72f988bf-86f1-41af-91ab-2d7cd011db47' contains more than one active subscription. First one will be selected for further use. To select another subscription, use Set-AzContext.
To override which subscription Connect-AzAccount selects by default, use `Update-AzConfig -DefaultSubscriptionForLogin 00000000-0000-0000-0000-000000000000`. Go to https://go.microsoft.com/fwlink/?linkid=2200610 for more information.

Account              SubscriptionName        TenantId                             Environment
-------              ----------------        --------                             -----------
[email protected] MSFT-CloudMS-CPT-PRD-01 72f988bf-86f1-41af-91ab-2d7cd011db47 AzureCloud


> Get-AzContext -ListAvailable

Name                                     Account             SubscriptionName    Environment         TenantId
----                                     -------             ----------------    -----------         --------
AzureSDKTest (0b1f6471-1bf0-4dda-aec3-c… [email protected]… AzureSDKTest        AzureCloud          54826b22-38d6-4fb…
MSFT-CloudMS-CPT-PRD-01 (2f96ae42-240b-… [email protected]… MSFT-CloudMS-CPT-P… AzureCloud          72f988bf-86f1-41a…

jiasli avatar Aug 02 '22 08:08 jiasli