private void CleanupRecipients(ADObjectId ouObjId, ITenantRecipientSession recipientSession) { ADPagedReader <ADRecipient> adpagedReader = recipientSession.FindPaged(ouObjId, QueryScope.SubTree, new ExistsFilter(ADRecipientSchema.ExternalDirectoryObjectId), null, 0); using (TenantRelocationThrottlingManager tenantRelocationThrottlingManager = new TenantRelocationThrottlingManager(recipientSession.SessionSettings.PartitionId.ForestFQDN)) { foreach (ADRecipient adrecipient in adpagedReader) { adrecipient.ExternalDirectoryObjectId = null; recipientSession.Save(adrecipient, true); recipientSession.Delete(adrecipient); tenantRelocationThrottlingManager.Throttle(); } } }
public static IEnumerable <ADUser> GetUMEnabledUsersInDatabase(MailboxDatabase database) { QueryFilter filter = UMMailbox.GetUMEnabledUserQueryFilter(database); foreach (PartitionId partitionId in ADAccountPartitionLocator.GetAllAccountPartitionIds(true)) { ADSessionSettings settings = ADSessionSettings.FromAllTenantsPartitionId(partitionId); ITenantRecipientSession session = DirectorySessionFactory.Default.CreateTenantRecipientSession(null, null, LcidMapper.DefaultLcid, true, ConsistencyMode.IgnoreInvalid, null, settings, 199, "GetUMEnabledUsersInDatabase", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\PartitionDataAggregator.cs"); ADPagedReader <ADRecipient> recipientReader = session.FindPaged(null, QueryScope.SubTree, filter, null, 0); foreach (ADRecipient recipient in recipientReader) { ADUser user = recipient as ADUser; if (user != null) { yield return(user); } } } yield break; }