Пример #1
0
        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();
        }