public SetCurrentContext ( string tenantId ) : Microsoft.Azure.Common.Authentication.Models.AzureContext | ||
tenantId | string | |
Résultat | Microsoft.Azure.Common.Authentication.Models.AzureContext |
protected override void ProcessRecord() { if (ParameterSetName == ContextParameterSet) { AzureRmProfileProvider.Instance.Profile.SetContextWithCache(new AzureContext(Context.Subscription, Context.Account, Context.Environment, Context.Tenant)); } 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)) { profileClient.SetCurrentContext(SubscriptionId, SubscriptionName, TenantId); } else { profileClient.SetCurrentContext(TenantId); } } WriteObject((PSAzureContext)AzureRmProfileProvider.Instance.Profile.Context); }
public override void ExecuteCmdlet() { if (ParameterSetName == ContextParameterSet) { AzureRmProfileProvider.Instance.Profile.SetContextWithCache(new AzureContext(Context.Subscription, Context.Account, Context.Environment, Context.Tenant)); } 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)) { profileClient.SetCurrentContext(SubscriptionId, SubscriptionName, TenantId); } else { profileClient.SetCurrentContext(TenantId); } } if (AzureRmProfileProvider.Instance.Profile.Context != null && AzureRmProfileProvider.Instance.Profile.Context.Subscription != null && AzureRmProfileProvider.Instance.Profile.Context.Subscription.State != null && !AzureRmProfileProvider.Instance.Profile.Context.Subscription.State.Equals( "Enabled", StringComparison.OrdinalIgnoreCase)) { WriteWarning(string.Format( Microsoft.Azure.Commands.Profile.Properties.Resources.SelectedSubscriptionNotActive, AzureRmProfileProvider.Instance.Profile.Context.Subscription.State)); } WriteObject((PSAzureContext)AzureRmProfileProvider.Instance.Profile.Context); }
protected override void ProcessRecord() { if (ParameterSetName == ContextParameterSet) { AzureRmProfileProvider.Instance.Profile.SetContextWithCache(new AzureContext(Context.Subscription, Context.Account, Context.Environment, Context.Tenant)); } else { var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile); profileClient.SetCurrentContext(SubscriptionId, TenantId); if (!string.IsNullOrWhiteSpace(SubscriptionName)) { AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name = SubscriptionName; } } WriteObject((PSAzureContext)AzureRmProfileProvider.Instance.Profile.Context); }
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(); } }