添加地址信息到Active Directory用户 [英] Adding address information to active directory users

查看:126
本文介绍了添加地址信息到Active Directory用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用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文档更多信息。

下面是结果:

这篇关于添加地址信息到Active Directory用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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