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

Multiple subscription with same name - Issue with Get-AzSubscription #19295

Closed
mlomat opened this issue Aug 23, 2022 · 3 comments · Fixed by #19335
Closed

Multiple subscription with same name - Issue with Get-AzSubscription #19295

mlomat opened this issue Aug 23, 2022 · 3 comments · Fixed by #19335
Assignees
Labels
Accounts Issues in Az.Accounts except authentication related customer-reported feature-request This issue requires a new behavior in the product in order be resolved.

Comments

@mlomat
Copy link

mlomat commented Aug 23, 2022

Description

Azure is allowing multiple subscriptions with this same name. Currently, cmdlet Get-AzSubscription -SubscriptionName "some name" will return some random first sub with name "some name" even you have mutliple subscriptions. In my opinion, it should throw exception that we have more than one sub with this name or return them all. If we want to keep it as it is, it should at least return Enabled subscription, because currently it's probably enumerating in alphabetic order by state and in case there is sub with same name disabled, cmdlet will return disabled sub instead of active one.

Issue script & Debug output

public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrWhiteSpace(this.SubscriptionName))
            {
                IAzureSubscription result;
                try
                {
        This line is giving only one subscription     -->       if (!this._client.TryGetSubscriptionByName(TenantId, this.SubscriptionName, out result))
                    {
                        ThrowSubscriptionNotFoundError(this.TenantId, this.SubscriptionName);
                    }

                    WriteObject(new PSAzureSubscription(result));
                }
                catch (AadAuthenticationException exception)
                {
                    ThrowTenantAuthenticationError(TenantId, exception);
                    throw;
                }

Environment data

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

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.9.1                 Az.Accounts

Error output

No response

@mlomat mlomat added bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Aug 23, 2022
@ghost ghost added customer-reported and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Aug 23, 2022
@mlomat
Copy link
Author

mlomat commented Aug 23, 2022

@dingmeng-xue dingmeng-xue added Accounts Issues in Az.Accounts except authentication related question The issue doesn't require a change to the product in order to be resolved. Most issues start as that feature-request This issue requires a new behavior in the product in order be resolved. and removed bug This issue requires a change to an existing behavior in the product in order to be resolved. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Aug 24, 2022
@dingmeng-xue
Copy link
Member

Thanks for reporting. IMHO, it makes sense that Get-AzSubscription -SubscriptionName returns all subscriptions according to its name no matter it is enabled or disabled. Then user can leverage PowerShell script to filter the result according to requirement. It is aligning with behavior of Get-AzSubscription

What's your thought?

@mlomat
Copy link
Author

mlomat commented Aug 24, 2022

@dingmeng-xue Yep - agree 100% especially that if you execute command without -SubscriptionName, it's giving you all subscriptions. Only exception is -SubscriptionId, because guid should be always unique.

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 customer-reported feature-request This issue requires a new behavior in the product in order be resolved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants