diff --git a/src/Common/Commands.ResourceManager.Common/RMProfileClient.cs b/src/Common/Commands.ResourceManager.Common/RMProfileClient.cs index c01d15ae4523..63ed7b2a1fd5 100644 --- a/src/Common/Commands.ResourceManager.Common/RMProfileClient.cs +++ b/src/Common/Commands.ResourceManager.Common/RMProfileClient.cs @@ -60,9 +60,10 @@ public AzureRMProfile Login(AzureAccount account, AzureEnvironment environment, { foreach(var tenant in ListAccountTenants(account, environment, password, promptBehavior)) { - if (TryGetTenantSubscription(account, environment, tenant.Id.ToString(), subscriptionId, password, ShowDialog.Auto, out newSubscription, out newTenant)) + AzureTenant tempTenant; + if (TryGetTenantSubscription(account, environment, tenant.Id.ToString(), subscriptionId, password, ShowDialog.Auto, out newSubscription, out tempTenant)) { - break; + newTenant = tempTenant; } } } @@ -251,7 +252,8 @@ private IEnumerable ListSubscriptionsForTenant(AzureAccount a environment, tenantId, password, - promptBehavior); + promptBehavior, + TokenCache.DefaultShared); using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient( new TokenCloudCredentials(accessToken.AccessToken), environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager))) diff --git a/src/Common/Commands.ResourceManager.Profile/Profile/SelectAzureRMProfile.cs b/src/Common/Commands.ResourceManager.Profile/Profile/SelectAzureRMProfile.cs index 7031f1f0f7e6..f31fdfcab16f 100644 --- a/src/Common/Commands.ResourceManager.Profile/Profile/SelectAzureRMProfile.cs +++ b/src/Common/Commands.ResourceManager.Profile/Profile/SelectAzureRMProfile.cs @@ -35,6 +35,11 @@ public class SelectAzureRMProfileCommand : AzureRMCmdlet [Parameter(ParameterSetName = ProfileFromDiskParameterSet, Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true)] public string Path { get; set; } + protected override void BeginProcessing() + { + // Do not access the DefaultContext when loading a profile + } + protected override void ProcessRecord() { if (!string.IsNullOrEmpty(Path))