_connection.Modify(entry.DN, new LdapModification(LdapModification.REPLACE, attributePassword));
return true; }
禁用用户
1 2 3 4 5 6 7 8 9 10 11 12 13
public static bool EnblaedUser(string loginName) { LdapEntry entry = GetUser(loginName); if (entry == null) { throw new Exception($"名为:{loginName} 的用户在AD中不存在"); }
LdapAttribute attributePassword = new LdapAttribute("userAccountControl", (66082).ToString()); _connection.Modify(entry.DN, new LdapModification(LdapModification.REPLACE, attributePassword));
return true; }
启用用户
1 2 3 4 5 6 7 8 9 10 11 12 13
public static bool EnblaedUser(string loginName) { LdapEntry entry = GetUser(loginName); if (entry == null) { throw new Exception($"名为:{loginName} 的用户在AD中不存在"); }
LdapAttribute attributePassword = new LdapAttribute("userAccountControl", (66080).ToString()); _connection.Modify(entry.DN, new LdapModification(LdapModification.REPLACE, attributePassword));
public static bool AddUserToGroup(string loginName, string groupDN) { LdapEntry entry = GetUser(loginName); if (entry == null) { throw new Exception($"名为:{loginName} 的用户在AD中不存在"); }
List<string> memberOf = entry.AttrStringValueArray("memberOf"); if (memberOf.Contains(groupDN)) { throw new Exception($"名为:{loginName} 的用户已经加入了组: {groupDN}"); }
LdapModification[] modGroup = new LdapModification[1]; LdapAttribute member = new LdapAttribute("member", entry.DN); modGroup[0] = new LdapModification(LdapModification.ADD, member);
public static bool RemoveUserFromGroup(string loginName, string groupDN) { LdapEntry entry = GetUser(loginName); if (entry == null) { throw new Exception($"名为:{loginName} 的用户在AD中不存在"); }
List<string> memberOf = entry.AttrStringValueArray("memberOf"); if (!memberOf.Contains(groupDN)) { throw new Exception($"名为:{loginName} 的用户不存在于组: {groupDN} 中"); }
LdapModification[] modGroup = new LdapModification[1]; LdapAttribute member = new LdapAttribute("member", entry.DN); modGroup[0] = new LdapModification(LdapModification.DELETE, member);