如何使用System.DirectoryServices.AccountManagement将用户添加到AD?

编程入门 行业动态 更新时间:2024-10-27 13:27:25
本文介绍了如何使用System.DirectoryServices.AccountManagement将用户添加到AD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用 3.5框架和C#,我试图从C#向AD添加新用户,但找不到任何示例。我看到PrincipalCollection对象具有重载的 add方法,但似乎无法弄清楚它是如何工作的。有人可以帮忙吗?

Using the 3.5 framework and C# I'm trying to add a new user to AD from C# and can't find any examples. I see that the PrincipalCollection object has an overloaded 'add' method but can't seem to figure out how it works. Can anyone help?

如何创建一个新的用户对象,将其添加到AD中。

How create a new user object, add it into AD.

第二,要添加新用户的用户实际上可能没有这样做的安全性。有没有一种方法可以模拟另一个将具有权限的用户帐户并以这种方式添加该帐户?

Secondly, the user that will be adding in new people may not actually have the security to do this. Is there a way that I can impersonate another user account that will have permissions and add the account that way?

推荐答案

您可以添加以下用户:

using (var context = new PrincipalContext(ContextType.Domain)) using (var user = new UserPrincipal(context) { UserPrincipalName = "username", Enabled = true }) { user.SetPassword("password"); user.Save(); }

Re:安全性,您可以将应用程序池标识设置为使用特权服务帐户有权写入Active Directory。或者,您可以为 PrincipalContext 使用构造函数重载,该重载采用LDAP连接的用户名和密码。

Re: security you can set the application pool identity to use a privileged service account that has permission to write to the Active Directory. Or you can use a constructor overload for PrincipalContext that takes a username and password for the LDAP connection.

更多推荐

如何使用System.DirectoryServices.AccountManagement将用户添加到AD?

本文发布于:2023-06-06 02:22:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/534716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   用户   System   DirectoryServices   AccountManagement

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!