2016-04-15 65 views

回答

2

以下是如何使用DirectoryEntryDirectorySearcher搜索已刪除的用戶。如果將底層對象設爲UserPrincipal確實很簡單,那麼可以使用castuser對象作爲UserPrincipal

public static void searchDeletedUsers() 
{ 
    using (DirectoryEntry entry = new DirectoryEntry("LDAP://yourldappath.com")) 
    { 
     using (DirectorySearcher searcher = new DirectorySearcher(entry)) 
     { 
     searcher.Filter = "(&(isDeleted=TRUE)(objectclass=user))"; 
     searcher.Tombstone = true; 
     var users = searcher.FindAll(); 
     foreach(var user in users) 
     { 
      //user will contain the deleted user object 
     } 
     } 
    } 
} 
相關問題