4
我正在使用System.DirectoryServices.AccountManagement命名空间类来添加和管理AD中的用户,但我似乎无法找到如何将地址信息添加到用户对象。我正在使用UserPrincipal类以编程方式向AD添加用户。将地址信息添加到活动目录用户
任何想法?
我正在使用System.DirectoryServices.AccountManagement命名空间类来添加和管理AD中的用户,但我似乎无法找到如何将地址信息添加到用户对象。我正在使用UserPrincipal类以编程方式向AD添加用户。将地址信息添加到活动目录用户
任何想法?
这里是要做到这一点,通过使用可扩展的呼叫样本:
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", "[email protected]");
/* Create a user principal object
*/
slxUser aSlxUser = new slxUser(domainContextMonou, "W.Zeidan", "[email protected]", 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 documentation找到更多信息。
下面是结果:
那是什么我一直在寻找for..thanks – 2011-05-02 14:27:23