Skip to content

Set-AzureRmContext doesn't work after using Select-AzureRmProfile #2387

@wangzq

Description

@wangzq

To reproduce:

# First login as usual, such as Add-AzureRmAccount
Save-AzureRmProfile -Path .\armprofile.json
# Create a new PowerShell session, or use current one
Select-AzureRmProfile -Path .\armprofile.json
Select-AzureRmSubscription -SubscriptionName '<your subscription name>'

The last command above will fail with following error:

Set-AzureRmContext : Cannot retrieve the dynamic parameters for the cmdlet. Cannot process argument because the value of argument "validValues" is out of range. Change argument "validValues" to  a value
that is within range.
Parameter name: validValues
Actual value was System.String[].

This is because the subscriptions list is empty or null in following code from SetAzureRMContext.cs, since we used Select-AzureRmProfile instead of Add-AzureRmAccount to login:

        private RuntimeDefinedParameterDictionary CreateDynamicParameterDictionary()
        {
            var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary();

            var subscriptionIdAttributes = new Collection<Attribute>
            {
                new ParameterAttribute
                {
                    ParameterSetName = SubscriptionIdParameterSet,
                    Mandatory = false,
                    HelpMessage = "Subscription",
                    ValueFromPipelineByPropertyName = true
                },
                new ValidateSetAttribute(AzureRmProfileProvider.Instance.Profile.Context.Account.GetPropertyAsArray(AzureAccount.Property.Subscriptions)),
            };

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions