Adding address information to active directory users(向 Active Directory 用户添加地址信息)
问题描述
我正在使用 System.DirectoryServices.AccountManagement 命名空间类在 AD 中添加和管理用户,但我似乎无法找到如何向用户对象添加地址信息.我正在使用 UserPrincipal 类以编程方式将用户添加到 AD.
有什么想法吗?
以下是使用可扩展性调用实现此目的的示例:
类 DSPrincipals{静态无效主(字符串 [] args){/* 检索主体上下文*/PrincipalContext domainContextMonou = new PrincipalContext(ContextType.Domain, "WM2008R2ENT:389", "ou=Monou,dc=dom,dc=fr", "jpb", "pass@1w0rd01");/* 创建一个用户主体对象*/slxUser aSlxUser = new slxUser(domainContextMonou, "W.Zeidan", "pass@1w0rd01", true);/* 将一些属性分配给用户主体*/aSlxUser.GivenName = "Wessam";aSlxUser.Surname = "Zeidan";aSlxUser.streetAddress = "Add1";/* 强制用户在下次登录时更改密码*/aSlxUser.ExpirePasswordNow();/* 将用户保存到目录*/aSlxUser.Save();Console.ReadLine();}}[目录对象类(用户")][DirectoryRdnPrefix("CN")]类 slxUser : UserPrincipal{公共 slxUser(PrincipalContext 上下文):基础(上下文){}public slxUser(PrincipalContext context, string samAccountName, string password, bool enabled ) : base(context, samAccountName, password, enabled){}[DirectoryProperty("streetAddress")]公共字符串 streetAddress{得到{object[] result = this.ExtensionGet("streetAddress");如果(结果!= null){返回(字符串)结果[0];}别的{返回空;}}set { this.ExtensionSet("streetAddress", value);}}}
您可以在 MSDN 文档中找到更多信息.>
结果如下:
I'm using System.DirectoryServices.AccountManagement namespace classes to add and manage users in AD, but I can't seem to find how to add Address information to user objects. I'm using the UserPrincipal class to add users programatically to AD.
Any ideas?
Here is a sample to do that by using extensibility call :
class DSPrincipals
{
static void Main(string[] args)
{
/* Retreiving a principal context
*/
PrincipalContext domainContextMonou = new PrincipalContext(ContextType.Domain, "WM2008R2ENT:389", "ou=Monou,dc=dom,dc=fr", "jpb", "pass@1w0rd01");
/* Create a user principal object
*/
slxUser aSlxUser = new slxUser(domainContextMonou, "W.Zeidan", "pass@1w0rd01", true);
/* assign some properties to the user principal
*/
aSlxUser.GivenName = "Wessam";
aSlxUser.Surname = "Zeidan";
aSlxUser.streetAddress = "Add1";
/* Force the user to change password at next logon
*/
aSlxUser.ExpirePasswordNow();
/* save the user to the directory
*/
aSlxUser.Save();
Console.ReadLine();
}
}
[DirectoryObjectClass("user")]
[DirectoryRdnPrefix("CN")]
class slxUser : UserPrincipal
{
public slxUser(PrincipalContext context)
: base(context) { }
public slxUser(PrincipalContext context, string samAccountName, string password, bool enabled ) : base(context, samAccountName, password, enabled)
{
}
[DirectoryProperty("streetAddress")]
public string streetAddress
{
get
{
object[] result = this.ExtensionGet("streetAddress");
if (result != null)
{
return (string)result[0];
}
else
{
return null;
}
}
set { this.ExtensionSet("streetAddress", value); }
}
}
You'll find more information in MSDN documentation.
Here is the result :
这篇关于向 Active Directory 用户添加地址信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:向 Active Directory 用户添加地址信息
基础教程推荐
- 从 VB6 迁移到 .NET/.NET Core 的最佳策略或工具 2022-01-01
- 我什么时候应该使用 GC.SuppressFinalize()? 2022-01-01
- 使用 SED 在 XML 标签之间提取值 2022-01-01
- C# - 将浮点数转换为整数...并根据余数更改整数 2022-01-01
- 创建属性设置器委托 2022-01-01
- Page.OnAppearing 中的 Xamarin.Forms Page.DisplayAlert 2022-01-01
- C# - 如何列出发布到 ASPX 页面的变量名称和值 2022-01-01
- 覆盖 Json.Net 中的默认原始类型处理 2022-01-01
- 如何使用OpenXML SDK将Excel转换为CSV? 2022-01-01
- 当键值未知时反序列化 JSON 2022-01-01