使用C#在Active Directory中删除用户 [英] Delete user in active directory using c#

查看:314
本文介绍了使用C#在Active Directory中删除用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一些code,但没有工作,首先抛出异常发生操作错误。 code --->

I've written some code but not works it throws Exception "An operations error occurred." code --->

DirectoryEntry dirEntry = new DirectoryEntry("LDAP path", "admin-username", "admin-password");
dirEntry.Properties["member"].Remove("username-delete");
dirEntry.CommitChanges();
dirEntry.Close();

给我一些想法,以摆脱这种东西..

give me some ideas to get out of this things..

推荐答案

如果你在.NET 3.5及以上,你应该看看 System.DirectoryServices.AccountManagement (S.DS.AM)命名空间。阅读所有关于它的:

If you're on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read all about it here:

  • Managing Directory Security Principals in the .NET Framework 3.5
  • MSDN docs on System.DirectoryServices.AccountManagement

基本上,你可以定义域范围内,并很容易地找到在AD用户和/或组:

Basically, you can define a domain context and easily find users and/or groups in AD:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find the user you want to delete
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   user.Delete();
}

新S.DS.AM使得它可以很容易地玩弄用户和组AD!

The new S.DS.AM makes it really easy to play around with users and groups in AD!

这篇关于使用C#在Active Directory中删除用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆