Skip to content

Commit 24a6f55

Browse files
author
Hovsep Mkrtchyan
committed
Fixed subscription.CurrentStorageAccountName display in azure cmdlets
1 parent 9a872b4 commit 24a6f55

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/ServiceManagement/Profile/Commands.Profile/Microsoft.WindowsAzure.Commands.Profile.format.ps1xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
<PropertyName>TenantId</PropertyName>
7777
</ListItem>
7878
<ListItem>
79-
<Label>CurrentStorageAccountName</Label>
80-
<ScriptBlock>$_.GetAccountName()</ScriptBlock>
79+
<PropertyName>CurrentStorageAccountName</PropertyName>
8180
</ListItem>
8281
</ListItems>
8382
</ListEntry>

src/ServiceManagement/Profile/Commands.Profile/Models/PsAzureSubscription.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ public PSAzureSubscription(AzureSubscription subscription, AzureSMProfile profil
3434
Accounts = profile.Accounts.Values.Where(a => a.HasSubscription(subscription.Id)).ToArray();
3535
IsDefault = subscription.IsPropertySet(AzureSubscription.Property.Default);
3636
IsCurrent = profile.Context != null && profile.Context.Subscription.Id == subscription.Id;
37-
CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount);
37+
CurrentStorageAccountName = GetAccountName(subscription.GetProperty(AzureSubscription.Property.StorageAccount));
3838
TenantId = subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants).FirstOrDefault();
3939
}
4040

41-
42-
4341
public string SubscriptionId { get; set; }
4442

4543
public string SubscriptionName { get; set; }
@@ -57,5 +55,19 @@ public PSAzureSubscription(AzureSubscription subscription, AzureSMProfile profil
5755
public string CurrentStorageAccountName { get; set; }
5856

5957
public string TenantId { get; set; }
58+
59+
public string GetAccountName(string storageAccount)
60+
{
61+
string accountName = null;
62+
63+
if (!string.IsNullOrWhiteSpace(storageAccount))
64+
{
65+
accountName = storageAccount.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
66+
.Where(s => s.StartsWith("accountname", StringComparison.OrdinalIgnoreCase))
67+
.Select( s => s.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries).Last())
68+
.FirstOrDefault();
69+
}
70+
return accountName;
71+
}
6072
}
6173
}

0 commit comments

Comments
 (0)