public override void ExecuteCmdlet()
        {
            var azureAccount = new AsAzureAccount
            {
                Type = ServicePrincipal ? AsAzureAccount.AccountType.ServicePrincipal : AsAzureAccount.AccountType.User
            };

            SecureString password = null;

            if (Credential != null)
            {
                azureAccount.Id = Credential.UserName;
                password        = Credential.Password;
            }

            if (ServicePrincipal)
            {
                azureAccount.Tenant = TenantId;

                if (!string.IsNullOrEmpty(ApplicationId))
                {
                    azureAccount.Id = ApplicationId;
                }
                if (!string.IsNullOrEmpty(CertificateThumbprint))
                {
                    azureAccount.CertificateThumbprint = CertificateThumbprint;
                }
            }

            if (ShouldProcess(string.Format(Resources.LoginTarget, AsEnvironment.Name), "log in"))
            {
                var currentProfile = AsAzureClientSession.Instance.Profile;
                var currentContext = currentProfile.Context;

                // If there is no current context create one. If there is one already then
                // if the current credentials (userid) match the one that is already in context then use it.
                // if either the userid that is logging in or the environment to which login is happening is
                // different than the one in the context then clear the current context and proceed to login.
                // At any given point in time, we should only have one context i.e. one user logged in to one
                // environment.
                if (currentContext == null || Credential == null ||
                    string.IsNullOrEmpty(currentContext.Account.Id) ||
                    !currentContext.Account.Id.Equals(Credential.UserName) ||
                    !RolloutEnvironment.Equals(currentContext.Environment.Name))
                {
                    AsAzureClientSession.Instance.SetCurrentContext(azureAccount, AsEnvironment);
                }
// TODO: Remove IfDef
#if NETSTANDARD
                var asAzureProfile = AsAzureClientSession.Instance.Login(currentProfile.Context, password, WriteWarning);
#else
                var asAzureProfile = AsAzureClientSession.Instance.Login(currentProfile.Context, password);
#endif

                WriteObject(asAzureProfile);
            }
        }
        public override void ExecuteCmdlet()
        {
            AsAzureAccount azureAccount = new AsAzureAccount();

            SecureString password = null;

            if (Credential != null)
            {
                azureAccount.Id = Credential.UserName;
                password        = Credential.Password;
            }

            if (ShouldProcess(string.Format(Resources.LoginTarget, AsEnvironment.Name), "log in"))
            {
                var currentProfile = AsAzureClientSession.Instance.Profile;
                var currentContext = currentProfile.Context;

                // If there is no current context create one. If there is one already then
                // if the current credentials (userid) match the one that is already in context then use it.
                // if either the userid that is logging in or the environment to which login is happening is
                // different than the one in the context then clear the current context and proceed to login.
                // At any given point in time, we should only have one context i.e. one user logged in to one
                // environment.
                if (currentContext == null || Credential == null ||
                    string.IsNullOrEmpty(currentContext.Account.Id) ||
                    !currentContext.Account.Id.Equals(Credential.UserName) ||
                    !RolloutEnvironment.Equals(currentContext.Environment.Name))
                {
                    AsAzureClientSession.Instance.SetCurrentContext(azureAccount, AsEnvironment);
                }

                var asAzureProfile = AsAzureClientSession.Instance.Login(currentProfile.Context, password);

                WriteObject(asAzureProfile);
            }
        }