由网友(总有贱婢勾引朕)分享简介:我用System.DirectoryServices.AccountManagement命名空间的类添加和管理用户的广告,但我似乎无法找到如何解决信息添加到用户对象。我使用的UserPrincipal类添加用户编程到AD。I'm using System.DirectoryServices.AccountManage...
我用System.DirectoryServices.AccountManagement命名空间的类添加和管理用户的广告,但我似乎无法找到如何解决信息添加到用户对象。我使用的UserPrincipal类添加用户编程到AD。
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.
任何想法?
推荐答案
下面是一个简单的做,通过使用可扩展的呼叫:
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); }
}
}
您会发现在 MSDN文档更多信息。
下面是结果:
相关推荐
最新文章