public override void ExecuteCmdlet()
{
if (ParameterSetName == ContextParameterSet)
{
if (ShouldProcess(string.Format(Resources.ChangingContextUsingPipeline, Context.Tenant, Context.Subscription),
Resources.ContextChangeWarning, string.Empty))
{
AzureRmProfileProvider.Instance.Profile.SetContextWithCache(new AzureContext(Context.Subscription,
Context.Account,
Context.Environment, Context.Tenant));
CompleteContextProcessing();
}
}
else if (ParameterSetName == SubscriptionNameParameterSet || ParameterSetName == SubscriptionIdParameterSet)
{
if (string.IsNullOrWhiteSpace(SubscriptionId)
&& string.IsNullOrWhiteSpace(SubscriptionName)
&& string.IsNullOrWhiteSpace(TenantId))
{
throw new PSInvalidOperationException(Resources.SetAzureRmContextNoParameterSet);
}
var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
if (!string.IsNullOrWhiteSpace(SubscriptionId) || !string.IsNullOrWhiteSpace(SubscriptionName))
{
if (ShouldProcess(string.Format(Resources.ChangingContextSubscription,
SubscriptionName ?? SubscriptionId),
Resources.SubscriptionChangeWarning , string.Empty))
{
profileClient.SetCurrentContext(SubscriptionId, SubscriptionName, TenantId);
CompleteContextProcessing();
}
}
else
{
if (ShouldProcess(string.Format(Resources.ChangingContextTenant, TenantId),
Resources.TenantChangeWarning, string.Empty))
{
profileClient.SetCurrentContext(TenantId);
CompleteContextProcessing();
}
}
}
else
{
CompleteContextProcessing();
}
}