Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jiasli opened this issue Mar 9, 2021 · 3 comments
Assignees
Labels
Accounts Issues in Az.Accounts except authentication related feature-request This issue requires a new behavior in the product in order be resolved.
Milestone

Comments

@jiasli
Copy link
Member

jiasli commented Mar 9, 2021

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 jiasli added the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Mar 9, 2021
@dingmeng-xue dingmeng-xue added Accounts Issues in Az.Accounts except authentication related feature-request This issue requires a new behavior in the product in order be resolved. and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Mar 9, 2021
@dingmeng-xue
Copy link
Member

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 dingmeng-xue added this to the Backlog milestone Mar 11, 2021
@dingmeng-xue
Copy link
Member

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

@jiasli
Copy link
Member Author

jiasli commented Aug 2, 2022

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
-------              ---------------- --------                             -----------
xxxxxx@microsoft.com 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
-------              ----------------        --------                             -----------
xxxxxx@microsoft.com 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… xxxxxx@microsoft.c… AzureSDKTest        AzureCloud          54826b22-38d6-4fb…
MSFT-CloudMS-CPT-PRD-01 (2f96ae42-240b-… xxxxxx@microsoft.c… MSFT-CloudMS-CPT-P… AzureCloud          72f988bf-86f1-41a…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accounts Issues in Az.Accounts except authentication related feature-request This issue requires a new behavior in the product in order be resolved.
Projects
None yet
Development

No branches or pull requests

3 participants