Skip to content

Commit 285c386

Browse files
author
Hovsep Mkrtchyan
committed
fixed issue #1484
1 parent fcb9cf9 commit 285c386

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/ResourceManager/Profile/Commands.Profile/Models/RMProfileClient.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,24 @@ private bool TryGetTenantSubscription(IAccessToken accessToken,
483483
}
484484
else
485485
{
486-
var subscriptions = subscriptionClient.Subscriptions.List().Subscriptions;
487-
if (subscriptions != null && subscriptions.Any())
486+
var subscriptions = (subscriptionClient.Subscriptions.List().Subscriptions ??
487+
new List<Microsoft.Azure.Subscriptions.Models.Subscription>())
488+
.Where(s => s.State.Equals("enabled", StringComparison.OrdinalIgnoreCase) ||
489+
s.State.Equals("warned", StringComparison.OrdinalIgnoreCase));
490+
491+
if (subscriptions.Any())
488492
{
489493
if (subscriptionName != null)
490494
{
491-
subscriptionFromServer = subscriptions.FirstOrDefault(s => s.DisplayName.Equals(subscriptionName, StringComparison.OrdinalIgnoreCase));
495+
subscriptionFromServer = subscriptions.FirstOrDefault(
496+
s => s.DisplayName.Equals(subscriptionName, StringComparison.OrdinalIgnoreCase));
492497
}
493498
else
494499
{
495-
if (subscriptions.Count > 1)
500+
if (subscriptions.Count() > 1)
496501
{
497502
WriteWarningMessage(string.Format(
498-
"TenantId '{0}' contains more than one subscription. First one will be selected for further use. " +
503+
"TenantId '{0}' contains more than one active subscription. First one will be selected for further use. " +
499504
"To select another subscription, use Set-AzureRmContext.",
500505
tenantId));
501506
}

0 commit comments

Comments
 (0)