protected override void InternalProcessRecord() { TaskLogger.LogEnter(); ADForest adforest; if (this.Forest == null) { adforest = ADForest.GetLocalForest(); } else { adforest = ADForest.GetForest(this.Forest, this.Credential); } List <ADServer> list = new List <ADServer>(); if (this.GlobalCatalog) { list.AddRange(adforest.FindAllGlobalCatalogs(false)); } else { if (this.DomainName == null) { using (ReadOnlyCollection <ADDomain> .Enumerator enumerator = adforest.FindDomains().GetEnumerator()) { while (enumerator.MoveNext()) { ADDomain addomain = enumerator.Current; list.AddRange(addomain.FindAllDomainControllers(false)); } goto IL_F3; } } ADDomain addomain2; if (this.Credential == null) { addomain2 = adforest.FindDomainByFqdn(this.DomainName.ToString()); } else { addomain2 = ADForest.FindExternalDomain(this.DomainName.ToString(), this.Credential); } if (addomain2 != null) { list.AddRange(addomain2.FindAllDomainControllers(false)); } else { base.WriteError(new DomainNotFoundException(this.DomainName.ToString()), ErrorCategory.InvalidArgument, null); } } IL_F3: this.WriteResult <ADServer>(list); TaskLogger.LogExit(); }
public static ADServer PickLocalDomainController() { ADServer adserver = DirectoryUtilities.DomainControllerFromName("localhost"); if (adserver != null && DirectoryUtilities.IsGlobalCatalog(adserver) && adserver.IsAvailable()) { return(adserver); } ADSite localSite = DirectoryUtilities.ConfigurationSession.GetLocalSite(); if (localSite == null) { throw new ADInitializationException(Strings.LocalSiteNotFound); } ADDomain addomain = ADForest.GetLocalForest().FindLocalDomain(); if (addomain == null) { throw new ADInitializationException(Strings.LocalDomainNotFoundException); } ReadOnlyCollection <ADServer> readOnlyCollection = addomain.FindAllDomainControllers(); foreach (ADServer adserver2 in readOnlyCollection) { if (adserver2.ValidateRead().Length == 0 && adserver2.Site.Equals(localSite.Id) && adserver2.IsAvailable() && DirectoryUtilities.IsGlobalCatalog(adserver2)) { return(adserver2); } } if (adserver != null) { return(adserver); } foreach (ADServer adserver3 in readOnlyCollection) { if (adserver3.ValidateRead().Length == 0 && adserver3.Site.Equals(localSite.Id) && adserver3.IsAvailable()) { return(adserver3); } } throw new ADInitializationException(Strings.NoDCsAvailableException(addomain.Name, localSite.Name)); }