Пример #1
0
        protected ADServerSettings CreateADServerSettingsForOrganization(bool useDCInAnySite = false)
        {
            ISessionState sessionState = this.CurrentTaskContext.SessionState;
            bool          flag         = false;

            if (sessionState != null)
            {
                flag = ExchangePropertyContainer.IsContainerInitialized(sessionState);
            }
            OrganizationId orgId = null;

            if (this.CurrentTaskContext.InvocationInfo != null && this.CurrentTaskContext.InvocationInfo.IsCmdletInvokedWithoutPSFramework && this.CurrentTaskContext.UserInfo != null)
            {
                orgId = this.CurrentTaskContext.UserInfo.CurrentOrganizationId;
            }
            else if (flag)
            {
                ExchangeRunspaceConfiguration exchangeRunspaceConfiguration = ExchangePropertyContainer.GetExchangeRunspaceConfiguration(sessionState);
                if (exchangeRunspaceConfiguration != null)
                {
                    orgId = exchangeRunspaceConfiguration.OrganizationId;
                }
            }
            return(this.CreateServerSettings(orgId, useDCInAnySite));
        }
Пример #2
0
 internal static bool InitializeExchangePropertyContainerIfNeeded(ISessionState sessionState, out ADObjectId executingUserId, out OrganizationId executingUserOrganizationId)
 {
     executingUserId             = null;
     executingUserOrganizationId = null;
     if (sessionState != null && !ExchangePropertyContainer.IsContainerInitialized(sessionState))
     {
         ExTraceGlobals.LogTracer.Information(0L, "ExchangePropertyContainer is not initialized. Case of Service, Setup or Powershell with manually added snapin");
         executingUserOrganizationId = TaskHelper.ResolveCurrentUserOrganization(out executingUserId);
         if (executingUserOrganizationId == null)
         {
             executingUserOrganizationId = OrganizationId.ForestWideOrgId;
         }
         ExchangePropertyContainer.InitExchangePropertyContainer(sessionState, executingUserOrganizationId, executingUserId);
         return(true);
     }
     return(false);
 }
Пример #3
0
 private void CheckVerboseDebugParameter()
 {
     if (this.context.SessionState != null && ExchangePropertyContainer.IsContainerInitialized(this.context.SessionState))
     {
         ExchangeRunspaceConfiguration exchangeRunspaceConfiguration = ExchangePropertyContainer.GetExchangeRunspaceConfiguration(this.context.SessionState);
         if (exchangeRunspaceConfiguration != null && this.context.InvocationInfo != null)
         {
             if (!exchangeRunspaceConfiguration.IsVerboseEnabled(this.context.InvocationInfo.CommandName))
             {
                 this.verboseDisabled = true;
                 TaskLogger.Trace("The cmdlet does not have Verbose parameter by RBAC check. WriteVerbose is disabled.", new object[0]);
             }
             if (!exchangeRunspaceConfiguration.IsDebugEnabled(this.context.InvocationInfo.CommandName))
             {
                 this.debugDisabled = true;
                 TaskLogger.Trace("The cmdlet does not have Debug parameter by RBAC check. WriteDebug is disabled.", new object[0]);
             }
         }
     }
 }
Пример #4
0
        internal static ExchangeRunspaceConfiguration UpdateExchangeRunspaceConfiguration(ISessionState sessionState)
        {
            WindowsIdentity current = WindowsIdentity.GetCurrent();
            ExchangeRunspaceConfiguration exchangeRunspaceConfiguration = new ExchangeRunspaceConfiguration(current);

            if (!ExchangePropertyContainer.IsContainerInitialized(sessionState))
            {
                ExchangePropertyContainer.InitExchangePropertyContainer(sessionState, exchangeRunspaceConfiguration);
            }
            else
            {
                ExchangePropertyContainer propertyContainer = ExchangePropertyContainer.GetPropertyContainer(sessionState);
                propertyContainer.exchangeRunspaceConfiguration = exchangeRunspaceConfiguration;
                if (propertyContainer.budget != null)
                {
                    propertyContainer.budget.Dispose();
                }
                propertyContainer.budget = ExchangePropertyContainer.AcquirePowerShellBudget(exchangeRunspaceConfiguration);
            }
            return(exchangeRunspaceConfiguration);
        }
Пример #5
0
        private void InitializeRunspaceServerSettings(object sender, EventArgs e)
        {
            ISessionState    sessionState     = this.CurrentTaskContext.SessionState;
            ADServerSettings adserverSettings = null;
            bool             flag             = false;
            bool             flag2            = false;
            string           value            = null;

            if (sessionState != null)
            {
                flag2 = ExchangePropertyContainer.IsContainerInitialized(sessionState);
                if (flag2)
                {
                    adserverSettings = ExchangePropertyContainer.GetServerSettings(sessionState);
                    if (adserverSettings != null)
                    {
                        value = "SessionState";
                    }
                }
            }
            if (adserverSettings == null)
            {
                adserverSettings = ADSessionSettings.GetProcessServerSettings();
                if (adserverSettings != null)
                {
                    value = "ProcessServerSettings";
                }
            }
            if (adserverSettings == null)
            {
                if (this.CurrentTaskContext.CommandShell != null)
                {
                    this.CurrentTaskContext.CommandShell.TryGetVariableValue <ADServerSettings>(ExchangePropertyContainer.ADServerSettingsVarName, out adserverSettings);
                }
                flag = (adserverSettings != null);
                if (adserverSettings != null)
                {
                    value = "CommandShell";
                }
            }
            if (TopologyProvider.CurrentTopologyMode == TopologyMode.ADTopologyService)
            {
                ADServerSettings cmdletADServerSettings = this.GetCmdletADServerSettings();
                if (cmdletADServerSettings != null)
                {
                    this.CurrentTaskContext.Items["CmdletServerSettings"] = cmdletADServerSettings;
                    value            = "ADTopologyService";
                    adserverSettings = cmdletADServerSettings;
                }
            }
            if (adserverSettings == null)
            {
                flag = true;
                if (TopologyProvider.CurrentTopologyMode == TopologyMode.Adam)
                {
                    if (this.CurrentTaskContext.InvocationInfo != null && this.CurrentTaskContext.InvocationInfo.IsVerboseOn)
                    {
                        this.CurrentTaskContext.CommandShell.WriteVerbose(Strings.VerboseInitializeRunspaceServerSettingsAdam);
                    }
                    if (Globals.InstanceType == InstanceType.NotInitialized)
                    {
                        Globals.InitializeSinglePerfCounterInstance();
                    }
                    value            = "Adam-SimpleServerSettings";
                    adserverSettings = new SimpleServerSettings();
                }
                else if (TopologyProvider.CurrentTopologyMode == TopologyMode.Ldap)
                {
                    if (this.CurrentTaskContext.InvocationInfo != null && this.CurrentTaskContext.CommandShell != null && this.CurrentTaskContext.InvocationInfo.IsVerboseOn)
                    {
                        this.CurrentTaskContext.CommandShell.WriteVerbose(Strings.VerboseInitializeRunspaceServerSettingsLocal);
                    }
                    Globals.InitializeMultiPerfCounterInstance("EMS");
                    value            = "Ldap-LocalCmdLineServerSettings";
                    adserverSettings = LocalCmdLineServerSettings.CreateLocalCmdLineServerSettings();
                }
                else
                {
                    if (this.CurrentTaskContext.InvocationInfo != null && this.CurrentTaskContext.InvocationInfo.IsVerboseOn)
                    {
                        this.CurrentTaskContext.CommandShell.WriteVerbose(Strings.VerboseInitializeRunspaceServerSettingsRemote);
                    }
                    adserverSettings = this.CreateADServerSettingsForOrganization(false);
                    if (adserverSettings == null)
                    {
                        value            = "GCRandomly";
                        adserverSettings = RunspaceServerSettings.CreateRunspaceServerSettings(false);
                    }
                }
            }
            if (flag)
            {
                if (flag2)
                {
                    ExchangePropertyContainer.SetServerSettings(sessionState, adserverSettings);
                }
                else
                {
                    sessionState.Variables[ExchangePropertyContainer.ADServerSettingsVarName] = adserverSettings;
                }
            }
            ADSessionSettings.SetThreadADContext(new ADDriverContext(adserverSettings, ContextMode.Cmdlet));
            LocalizedString localizedString = LocalizedString.Empty;

            if (this.CurrentTaskContext.InvocationInfo != null)
            {
                localizedString = TaskVerboseStringHelper.GetADServerSettings(this.CurrentTaskContext.InvocationInfo.CommandName, adserverSettings);
                if (this.CurrentTaskContext.InvocationInfo.IsVerboseOn && !string.Equals(this.CurrentTaskContext.InvocationInfo.CommandName, "Write-ExchangeSetupLog", StringComparison.OrdinalIgnoreCase) && this.CurrentTaskContext.CommandShell != null)
                {
                    this.CurrentTaskContext.CommandShell.WriteVerbose(localizedString);
                }
            }
            CmdletLogger.SafeSetLogger(this.CurrentTaskContext.UniqueId, RpsCmdletMetadata.RunspaceSettingsCreationHint, value);
            CmdletLogHelper.LogADServerSettings(this.CurrentTaskContext.UniqueId, adserverSettings);
            if (ExTraceGlobals.LogTracer.IsTraceEnabled(TraceType.InfoTrace))
            {
                ExTraceGlobals.LogTracer.Information <LocalizedString>(0L, "Cmdlet ADServerSettings {0}", localizedString);
            }
        }