internal override RunspaceServerSettings CreateRunspaceServerSettings() { string runspaceServerSettingsToken = this.GetRunspaceServerSettingsToken(); if (runspaceServerSettingsToken == null) { return(RunspaceServerSettings.CreateRunspaceServerSettings(false)); } OrganizationId organizationId = RbacPrincipal.Current.RbacConfiguration.OrganizationId; if (VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Eac.OrgIdADSeverSettings.Enabled&& organizationId != null && RbacPrincipal.Current.IsAdmin && !OrganizationId.ForestWideOrgId.Equals(organizationId) && !ADSessionSettings.IsForefrontObject(organizationId.PartitionId)) { return(RunspaceServerSettings.CreateGcOnlyRunspaceServerSettings(runspaceServerSettingsToken.ToLowerInvariant(), organizationId.PartitionId.ForestFQDN, false)); } return(RunspaceServerSettings.CreateGcOnlyRunspaceServerSettings(runspaceServerSettingsToken.ToLowerInvariant(), false)); }
protected override void InitializeRunspace(Runspace runspace) { base.InitializeRunspace(runspace); try { RunspaceServerSettings runspaceServerSettings = RunspaceServerSettings.CreateRunspaceServerSettings(false); runspaceServerSettings.ViewEntireForest = true; runspace.SessionStateProxy.SetVariable(ExchangePropertyContainer.ADServerSettingsVarName, runspaceServerSettings); } catch (ADTransientException) { throw; } catch (ADExternalException) { throw; } }
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); } }