Skip to content

Commit 98534cd

Browse files
author
Hovsep Mkrtchyan
committed
Fixed help information for Set-AzureRmContext
1 parent 4da3ac5 commit 98534cd

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/ResourceManager/Profile/Commands.Profile/Context/SetAzureRMContext.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,19 @@ protected override void ProcessRecord()
5757
AzureRmProfileProvider.Instance.Profile.SetContextWithCache(new AzureContext(Context.Subscription, Context.Account,
5858
Context.Environment, Context.Tenant));
5959
}
60+
else if (ParameterSetName == SubscriptionIdParameterSet)
61+
{
62+
var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
63+
profileClient.SetCurrentContext(SubscriptionId, TenantId);
64+
}
6065
else if (ParameterSetName == SubscriptionNameParameterSet)
6166
{
67+
if(string.IsNullOrWhiteSpace(TenantId) &&
68+
string.IsNullOrWhiteSpace(SubscriptionName))
69+
{
70+
throw new PSInvalidOperationException(Resources.SetAzureRmContextNoParameterSet);
71+
}
72+
6273
var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
6374
AzureSubscription subscription = null;
6475
string tenantId = AzureRmProfileProvider.Instance.Profile.Context.Tenant.Id.ToString();
@@ -94,14 +105,10 @@ protected override void ProcessRecord()
94105
{
95106
// authenticate with just tenant id
96107
var accessToken = profileClient.AcureAccessToken(tenantId);
97-
profileClient.SetCurrentContext(tenantId);
108+
profileClient.SetCurrentContext(accessToken.TenantId);
98109
}
99110
}
100-
else if (ParameterSetName == SubscriptionIdParameterSet)
101-
{
102-
var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
103-
profileClient.SetCurrentContext(SubscriptionId, TenantId);
104-
}
111+
105112
WriteObject((PSAzureContext)AzureRmProfileProvider.Instance.Profile.Context);
106113
}
107114
}

src/ResourceManager/Profile/Commands.Profile/Microsoft.Azure.Commands.Profile.dll-Help.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ Subscription Name: Contoso Subscription 1</maml:para>
21092109
</maml:description>
21102110
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
21112111
</command:parameter>
2112-
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
2112+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
21132113
<maml:name>SubscriptionId</maml:name>
21142114
<maml:description>
21152115
<maml:para>The Subscription Id for executed cmdlets to use.</maml:para>
@@ -2189,7 +2189,7 @@ Subscription Name: Contoso Subscription 1</maml:para>
21892189
<command:parameterValue required="true" variableLength="false">AzureTenant</command:parameterValue>
21902190
</command:parameter>
21912191
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
2192-
<maml:name>Subscription</maml:name>
2192+
<maml:name>SubscriptionId</maml:name>
21932193
<maml:description>
21942194
<maml:para>The subscription to target in this session.</maml:para>
21952195
</maml:description>

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@
144144
<data name="NoValidTenant" xml:space="preserve">
145145
<value>Please provide a valid tenant Id on the command line or execute Login-AzureRmAccount.</value>
146146
</data>
147+
<data name="SetAzureRmContextNoParameterSet" xml:space="preserve">
148+
<value>Please provide either a subscription ID, subscription name, tenant Id or domain.</value>
149+
</data>
147150
<data name="SubscriptionNameNotFoundError" xml:space="preserve">
148151
<value>Unable to find subscription with name '{0}'.</value>
149152
</data>

0 commit comments

Comments
 (0)