@@ -35,7 +35,8 @@ namespace Microsoft.WindowsAzure.Commands.Profile
35
35
[ OutputType ( typeof ( AzureSubscription ) ) ]
36
36
public class GetAzureSubscriptionCommand : SubscriptionCmdletBase
37
37
{
38
- public GetAzureSubscriptionCommand ( ) : base ( true )
38
+ public GetAzureSubscriptionCommand ( )
39
+ : base ( true )
39
40
{
40
41
41
42
}
@@ -64,8 +65,17 @@ public override void ExecuteCmdlet()
64
65
switch ( ParameterSetName )
65
66
{
66
67
case "ByName" :
67
- WriteSubscriptions ( ProfileClient . RefreshSubscriptions ( Profile . Context . Environment )
68
- . Where ( s => SubscriptionName == null || s . Name . Equals ( SubscriptionName , StringComparison . InvariantCultureIgnoreCase ) ) ) ;
68
+ IEnumerable < AzureSubscription > subscriptions = new AzureSubscription [ 0 ] ;
69
+ if ( Profile . Context != null && Profile . Context . Environment != null )
70
+ {
71
+ subscriptions = ProfileClient . RefreshSubscriptions ( Profile . Context . Environment )
72
+ . Where (
73
+ s =>
74
+ SubscriptionName == null ||
75
+ s . Name . Equals ( SubscriptionName , StringComparison . InvariantCultureIgnoreCase ) ) ;
76
+ }
77
+
78
+ WriteSubscriptions ( subscriptions ) ;
69
79
break ;
70
80
case "ById" :
71
81
WriteSubscriptions ( ProfileClient . GetSubscription ( new Guid ( SubscriptionId ) ) ) ;
@@ -86,7 +96,7 @@ public void GetDefault()
86
96
if ( defaultSubscription == null )
87
97
{
88
98
WriteError ( new ErrorRecord (
89
- new InvalidOperationException ( Resources . InvalidDefaultSubscription ) ,
99
+ new InvalidOperationException ( Resources . InvalidDefaultSubscription ) ,
90
100
string . Empty ,
91
101
ErrorCategory . InvalidData , null ) ) ;
92
102
}
@@ -118,7 +128,7 @@ public void GetCurrent()
118
128
119
129
private void WriteSubscriptions ( params AzureSubscription [ ] subscriptions )
120
130
{
121
- WriteSubscriptions ( ( IEnumerable < AzureSubscription > ) subscriptions ) ;
131
+ WriteSubscriptions ( ( IEnumerable < AzureSubscription > ) subscriptions ) ;
122
132
}
123
133
124
134
private void WriteSubscriptions ( IEnumerable < AzureSubscription > subscriptions )
0 commit comments