【问题标题】:Adding address information to active directory users向 Active Directory 用户添加地址信息
【发布时间】:2011-05-02 09:07:48
【问题描述】:

我正在使用 System.DirectoryServices.AccountManagement 命名空间类在 AD 中添加和管理用户,但我似乎找不到如何将地址信息添加到用户对象。我正在使用 UserPrincipal 类以编程方式将用户添加到 AD。

有什么想法吗?

【问题讨论】:

    标签: c# active-directory


    【解决方案1】:

    这是一个使用可扩展性调用的示例:

      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 documentation 中找到更多信息。

    结果如下:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多