How can you find a user in active directory from C#?

后端 未结 8 696
时光取名叫无心
时光取名叫无心 2020-12-24 08:13

I\'m trying to figure out how to search AD from C# similarly to how \"Find Users, Contacts, and Groups\" works in the Active Directory Users and Computers tool. I have a str

8条回答
  •  情书的邮戳
    2020-12-24 08:43

    To add onto Miyagi's answer....

    Here's a filter/query to apply to DirectorySearcher

    DirectorySearcher ds = new DirectorySearcher();
    
    ds.Filter = "samaccountname=" + userName;
    
    SearchResult result = ds.FindOne();
    

提交回复
热议问题