private void ExtractRbacDataFromRunspace(object sender, EventArgs e) { ADObjectId adobjectId = null; OrganizationId organizationId = null; ExchangePropertyContainer.InitializeExchangePropertyContainerIfNeeded(this.context.SessionState, out adobjectId, out organizationId); ExchangeRunspaceConfiguration exchangeRunspaceConfiguration = null; if (this.context.SessionState != null) { exchangeRunspaceConfiguration = ExchangePropertyContainer.GetExchangeRunspaceConfiguration(this.context.SessionState); } OrganizationId organizationId2; string executingUserIdentityName; SmtpAddress executingWindowsLiveId; if (exchangeRunspaceConfiguration == null) { if (this.context.SessionState != null) { organizationId = (organizationId ?? ExchangePropertyContainer.GetExecutingUserOrganizationId(this.context.SessionState)); adobjectId = (adobjectId ?? ExchangePropertyContainer.GetExecutingUserId(this.context.SessionState)); } organizationId2 = organizationId; executingUserIdentityName = ((adobjectId == null) ? string.Empty : adobjectId.Name); } else { exchangeRunspaceConfiguration.TryGetExecutingUserId(out adobjectId); executingUserIdentityName = exchangeRunspaceConfiguration.IdentityName; exchangeRunspaceConfiguration.TryGetExecutingWindowsLiveId(out executingWindowsLiveId); organizationId = (exchangeRunspaceConfiguration.PartnerMode ? OrganizationId.ForestWideOrgId : exchangeRunspaceConfiguration.OrganizationId); organizationId2 = exchangeRunspaceConfiguration.OrganizationId; SecurityIdentifier value; exchangeRunspaceConfiguration.TryGetExecutingUserSid(out value); CmdletLogger.SafeSetLogger(this.context.UniqueId, RpsCmdletMetadata.ExecutingUserSid, value); } if (this.context.InvocationInfo != null && this.context.InvocationInfo.IsVerboseOn && !TaskLogger.IsSetupLogging) { string executingUserId = (adobjectId != null) ? adobjectId.ToCanonicalName() : string.Empty; string executingUserOrganizationId = (organizationId != null) ? organizationId.ToString() : string.Empty; string currentOrganizationId = (organizationId2 != null) ? organizationId2.ToString() : string.Empty; if (this.context.CommandShell != null) { this.context.CommandShell.WriteVerbose(Strings.VerboseExecutingUserContext(executingUserId, executingUserOrganizationId, currentOrganizationId, (exchangeRunspaceConfiguration == null) ? Strings.DisabledString : Strings.EnabledString)); } } this.context.ExchangeRunspaceConfig = exchangeRunspaceConfiguration; this.context.UserInfo = new TaskUserInfo(organizationId, organizationId2, adobjectId, executingUserIdentityName, executingWindowsLiveId); }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); ADForest localForest = ADForest.GetLocalForest(); this.rootDomain = localForest.FindRootDomain(); this.topLevelDomains = localForest.FindTopLevelDomains(); List <string> list = new List <string>(); ReadOnlyCollection <ADDomain> readOnlyCollection = localForest.FindDomains(); foreach (ADDomain addomain in readOnlyCollection) { if (!list.Contains(addomain.Fqdn)) { list.Add(addomain.Fqdn); } } IConfigurationSession configurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 85, "InternalProcessRecord", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\ExchangeServer\\GetUserPrincipalNamesSuffix.cs"); configurationSession.UseGlobalCatalog = true; configurationSession.EnforceDefaultScope = false; ADCrossRefContainer[] array = configurationSession.Find <ADCrossRefContainer>(null, QueryScope.SubTree, null, null, 0); if (array != null && array.Length > 0) { foreach (string item in array[0].UPNSuffixes) { if (!list.Contains(item)) { list.Add(item); } } } IConfigurationSession configurationSession2 = (IConfigurationSession)this.CreateSession(); if (this.OrganizationalUnit != null) { ExtendedOrganizationalUnit extendedOrganizationalUnit = null; IEnumerable <ExtendedOrganizationalUnit> objects = this.OrganizationalUnit.GetObjects <ExtendedOrganizationalUnit>(null, configurationSession2); using (IEnumerator <ExtendedOrganizationalUnit> enumerator3 = objects.GetEnumerator()) { if (enumerator3.MoveNext()) { extendedOrganizationalUnit = enumerator3.Current; if (enumerator3.MoveNext()) { base.WriteError(new ManagementObjectAmbiguousException(Strings.SpecifiedOUNotUnique), ErrorCategory.InvalidArgument, extendedOrganizationalUnit); } } else { base.WriteError(new ManagementObjectNotFoundException(Strings.SpecifiedOUNotFound), ErrorCategory.InvalidArgument, extendedOrganizationalUnit); } } configurationSession2.UseConfigNC = false; configurationSession2.UseGlobalCatalog = false; extendedOrganizationalUnit = configurationSession2.Read <ExtendedOrganizationalUnit>(extendedOrganizationalUnit.Id); if (extendedOrganizationalUnit != null) { foreach (string item2 in extendedOrganizationalUnit.UPNSuffixes) { if (!list.Contains(item2)) { list.Add(item2); } } } ADObjectId adobjectId = extendedOrganizationalUnit.Id.DomainId; bool flag = false; while (!flag) { string text = adobjectId.ToCanonicalName(); if (this.IsTopLevelDomain(text)) { flag = true; } if (!string.Equals(text, this.rootDomain.Fqdn, StringComparison.InvariantCultureIgnoreCase) && !list.Contains(text)) { list.Add(text); } adobjectId = adobjectId.Parent; } } foreach (string sendToPipeline in list) { base.WriteObject(sendToPipeline); } TaskLogger.LogExit(); }
protected override void InternalValidate() { TaskLogger.LogEnter(); base.InternalValidate(); if (base.HasErrors) { return; } if (!(base.ServerSettings is RunspaceServerSettings)) { this.WriteWarning(Strings.WarningSettingsNotModifiable); this.settingsNotModifiable = true; return; } if (base.ServerSettings == null && (this.RunspaceServerSettings == null || this.RunspaceServerSettings.RawServerSettings == null)) { base.WriteError(new InvalidOperationException(Strings.ErrorRunspaceServerSettingsNotFound), ErrorCategory.InvalidOperation, this); } if (base.Fields.IsModified("Instance")) { this.modifiedServerSettings = ((this.RunspaceServerSettings.RawServerSettings != null) ? this.RunspaceServerSettings.RawServerSettings : ((RunspaceServerSettings)base.ServerSettings.Clone())); this.ConfigurationDomainController = this.RunspaceServerSettings.UserPreferredConfigurationDomainController; this.PreferredGlobalCatalog = this.RunspaceServerSettings.UserPreferredGlobalCatalog; this.RecipientViewRoot = this.RunspaceServerSettings.RecipientViewRoot; this.SetPreferredDomainControllers = this.RunspaceServerSettings.UserPreferredDomainControllers; this.ViewEntireForest = this.RunspaceServerSettings.ViewEntireForest; this.WriteOriginatingChangeTimestamp = this.RunspaceServerSettings.WriteOriginatingChangeTimestamp; this.WriteShadowProperties = this.RunspaceServerSettings.WriteShadowProperties; } else { this.modifiedServerSettings = (RunspaceServerSettings)base.ServerSettings.Clone(); } if (base.Fields.IsModified("ViewEntireForest")) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingViewEntireForest(this.ViewEntireForest.ToString())); } this.modifiedServerSettings.ViewEntireForest = this.ViewEntireForest; if (this.ViewEntireForest) { if (!string.IsNullOrEmpty(this.RecipientViewRoot)) { base.WriteError(new ArgumentException(Strings.ErrorSetRecipientViewRootAndViewEntireForestToTrue), ErrorCategory.InvalidArgument, this); } } else if (!string.IsNullOrEmpty(this.RecipientViewRoot)) { this.VerifyAndSetRecipientViewRoot(this.RecipientViewRoot); } else if (base.Fields.IsModified("RecipientViewRoot")) { base.WriteError(new ArgumentException(Strings.ErrorRecipientViewRootEmptyAndViewEntireForestToFalse), ErrorCategory.InvalidArgument, this); } else if (base.ScopeSet.RecipientReadScope != null && base.ScopeSet.RecipientReadScope.Root != null) { this.modifiedServerSettings.RecipientViewRoot = base.ScopeSet.RecipientReadScope.Root; } } else if (base.Fields.IsModified("RecipientViewRoot")) { if (!string.IsNullOrEmpty(this.RecipientViewRoot)) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingViewEntireForest(false.ToString())); } this.modifiedServerSettings.ViewEntireForest = false; this.VerifyAndSetRecipientViewRoot(this.RecipientViewRoot); } else { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingViewEntireForest(true.ToString())); } this.modifiedServerSettings.ViewEntireForest = true; } } if (this.PreferredServer != null) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingPreferredServer("PreferredGlobalCatalog", this.PreferredServer)); } this.modifiedServerSettings.SetUserPreferredGlobalCatalog(this.PreferredServer); if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingPreferredServer("ConfigurationDomainController", this.PreferredServer)); } this.modifiedServerSettings.SetUserConfigurationDomainController(this.PreferredServer); if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingPreferredServer("SetPreferredDomainControllers", this.PreferredServer)); } ADObjectId adobjectId; Fqdn fqdn; this.modifiedServerSettings.AddOrReplaceUserPreferredDC(this.PreferredServer, out adobjectId, out fqdn); } if (base.Fields.IsModified("PreferredGlobalCatalog")) { if (this.PreferredGlobalCatalog == null) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseClearPreferredServer("PreferredGlobalCatalog")); } this.modifiedServerSettings.ClearUserPreferredGlobalCatalog(); } else if (!string.Equals(this.PreferredGlobalCatalog, this.modifiedServerSettings.UserPreferredGlobalCatalog, StringComparison.OrdinalIgnoreCase)) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingPreferredServer("PreferredGlobalCatalog", this.PreferredGlobalCatalog)); } this.modifiedServerSettings.SetUserPreferredGlobalCatalog(this.PreferredGlobalCatalog); } } if (base.Fields.IsModified("ConfigurationDomainController")) { if (this.ConfigurationDomainController == null) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseClearPreferredServer("ConfigurationDomainController")); } this.modifiedServerSettings.ClearUserConfigurationDomainController(); } else if (!string.Equals(this.ConfigurationDomainController, this.modifiedServerSettings.UserConfigurationDomainController, StringComparison.OrdinalIgnoreCase)) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingPreferredServer("ConfigurationDomainController", this.ConfigurationDomainController)); } this.modifiedServerSettings.SetUserConfigurationDomainController(this.ConfigurationDomainController); } } if (base.Fields.IsModified("SetPreferredDomainControllers")) { if (this.SetPreferredDomainControllers == null || this.SetPreferredDomainControllers.Count == 0) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseClearAllPreferredDC); } this.modifiedServerSettings.ClearAllUserPreferredDCs(); } else { foreach (Fqdn fqdn2 in this.SetPreferredDomainControllers) { if (!this.modifiedServerSettings.UserPreferredDomainControllers.Contains(fqdn2)) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingPreferredServer("SetPreferredDomainControllers", fqdn2)); } ADObjectId adobjectId2 = null; Fqdn fqdn3 = null; this.modifiedServerSettings.AddOrReplaceUserPreferredDC(fqdn2, out adobjectId2, out fqdn3); if (fqdn3 != null) { this.WriteWarning(Strings.WarningPreferredServerReplaced(fqdn2, fqdn3, adobjectId2.ToCanonicalName())); } } } } } if (base.Fields.IsModified("WriteOriginatingChangeTimestamp")) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingWriteOriginatingChangeTimestamp(this.WriteOriginatingChangeTimestamp.ToString())); } this.modifiedServerSettings.WriteOriginatingChangeTimestamp = this.WriteOriginatingChangeTimestamp; } if (base.Fields.IsModified("WriteShadowProperties")) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingWriteShadowProperties(this.WriteOriginatingChangeTimestamp.ToString())); } this.modifiedServerSettings.WriteShadowProperties = this.WriteShadowProperties; } if (base.Fields.IsModified("DisableGls")) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingDisableGls(this.DisableGls.ToString())); } this.modifiedServerSettings.DisableGls = this.DisableGls; } if (base.Fields.IsModified("ForceADInTemplateScope")) { if (base.IsVerboseOn) { base.WriteVerbose(Strings.VerboseSettingDisableAggregation(this.ForceADInTemplateScope.ToString())); } this.modifiedServerSettings.ForceADInTemplateScope = this.ForceADInTemplateScope; } TaskLogger.LogExit(); }