向 Active Directory 用户添加地址信息

Adding address information to active directory users(向 Active Directory 用户添加地址信息)
本文介绍了向 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 用户添加地址信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to determine the type (AD User vs. AD Group) of an account?(如何确定帐户的类型(AD 用户与 AD 组)?)
How to resolve quot;The server does not support the control. The control is critical.quot; Active Directory error(如何解决“服务器不支持控件.控制至关重要.活动目录错误)
How to authenticate users with a customer#39;s (remote) active directory server(如何使用客户的(远程)活动目录服务器对用户进行身份验证)
How to know if my DirectoryEntry is really connected to my LDAP directory?(如何知道我的 DirectoryEntry 是否真的连接到我的 LDAP 目录?)
Add member to AD group from a trusted domain(将成员从受信任的域添加到 AD 组)
How to retrieve Users in a Group, including primary group users(如何检索组中的用户,包括主要组用户)