DirectoryEntry对象在C#中用于操作和管理目录服务(也称为Active Directory)中的目录项。下面是一些常用的DirectoryEntry对象的使用方法:
DirectoryEntry entry = new DirectoryEntry("LDAP://servername/ou=users,dc=example,dc=com", "admin", "password");
string username = entry.Properties["sAMAccountName"].Value.ToString();
string email = entry.Properties["mail"].Value.ToString();
entry.Properties["displayName"].Value = "John Doe";
entry.CommitChanges();
DirectoryEntry newUser = entry.Children.Add("CN=New User", "user");
newUser.Properties["sAMAccountName"].Value = "newuser";
newUser.Properties["givenName"].Value = "New";
newUser.Properties["sn"].Value = "User";
newUser.Properties["userPrincipalName"].Value = "newuser@example.com";
newUser.CommitChanges();
entry.Children.Remove("CN=New User");
foreach (DirectoryEntry child in entry.Children)
{
Console.WriteLine(child.Name);
}
以上是一些常用的DirectoryEntry对象的使用示例。请注意,使用DirectoryEntry对象操作Active Directory时需要相应的权限。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: C#字符串内存管理的方法是什么