private IEnumerable <ADRawEntry> FindObjects(ADObjectId[] identities, IEnumerable <PropertyDefinition> propertiesToRead) { if (ADSessionSettings.GetThreadServerSettings() == null) { EcpRunspaceFactory ecpRunspaceFactory = new EcpRunspaceFactory(new InitialSessionStateSectionFactory()); ADSessionSettings.SetThreadADContext(new ADDriverContext(ecpRunspaceFactory.CreateRunspaceServerSettings(), ContextMode.Cmdlet)); } IDirectorySession session = this.CreateAdSession(); List <QueryFilter> filters = new List <QueryFilter>(this.properMaxCustomFilterTreeSize); int filterLenRemain = 31197; int i = 0; while (i < identities.Length) { QueryFilter idFilter = new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Id, identities[i]); filters.Add(idFilter); string ldapIdFilter = LdapFilterBuilder.LdapFilterFromQueryFilter(idFilter); if (ldapIdFilter.Length > filterLenRemain || filters.Count == this.properMaxCustomFilterTreeSize || i == identities.Length - 1) { ADPagedReader <ADRawEntry> entries = null; try { entries = session.FindPagedADRawEntry(null, QueryScope.SubTree, new OrFilter(filters.ToArray()), null, this.properMaxCustomFilterTreeSize, propertiesToRead); } catch (ADFilterException) { if (this.isFirstError) { i -= filters.Count; this.properMaxCustomFilterTreeSize /= 2; filters.Clear(); filterLenRemain = 31197; this.isFirstError = false; goto IL_22E; } throw; } foreach (ADRawEntry entry in entries) { yield return(entry); } filters.Clear(); filterLenRemain = 31197; goto IL_216; } goto IL_216; IL_22E: i++; continue; IL_216: filterLenRemain -= ldapIdFilter.Length; goto IL_22E; } yield break; }