get deleted objects from AD

228 Views Asked by At

I'm using the Novell.Directory.Ldap.NETStandard library to read out users and groups from Active Directory. That all works fine so far. Now I need to get all deleted objects from AD, which doesn't work so far.

I was able to see the deleted user with the ldp.exe on my server, but have not been able to access the CN=Deleted Objects,DC=myDC DN from the Novell Library.

Here's how I tried to get the deleted users:

  IEnumerable <string> GetDeletedUsers(ILdapConnection conn)
        {
            string searchFilter = "(objectclass=person)";
            List<string> objectList = new List<string>();

            LdapSearchResults searchResults = PrepareSearch(conn, "CN=Deleted Objects,DC=myDC", searchFilter);
            while (searchResults.hasMore())
            {
                var nextEntry = searchResults.next(); // hits and then goes to timeout
                String dN = nextEntry.getAttribute("distinguishedName").StringValue;
                objectList.Add(dN);
            }

            return objectList;
        }


 LdapSearchResults PrepareSearch(ILdapConnection conn, string searchStart, string searchfilter)
        {
            LdapSearchConstraints constraints = new LdapSearchConstraints();
            constraints.TimeLimit = 30000;

            LdapSearchResults searchResults = conn.Search
            (
                searchStart,
                LdapConnection.SCOPE_SUB,
                searchfilter,
                null,
                false,
                constraints
            );
            return searchResults;
        }

For this I always get the "Novell.Directory.Ldap.LdapException: 'No Such Object'" when next is called on the resultset. Is there a reason I can't access it like I do?

0

There are 0 best solutions below