Active directory 为所有广告用户vCard的导出编写脚本的方法

Active directory 为所有广告用户vCard的导出编写脚本的方法,active-directory,export,vcf-vcard,Active Directory,Export,Vcf Vcard,我正在寻找一种简单的方法,将所有active directory用户信息导出到每个用户的唯一vCard中。我想在vcard上留下一些信息,比如家庭电话和紧急联系人。我环顾了一下网络,几乎没有找到任何东西。任何帮助都将不胜感激 我怀疑会有一个非常简单的方法。最终,你需要 枚举所有用户(或其子集) 迭代生成的用户列表 将每个用户的数据导出到VCard 对于搜索和迭代部分,您可以使用PrincipalSearcher进行搜索: // create your domain context using (

我正在寻找一种简单的方法,将所有active directory用户信息导出到每个用户的唯一vCard中。我想在vcard上留下一些信息,比如家庭电话和紧急联系人。我环顾了一下网络,几乎没有找到任何东西。任何帮助都将不胜感激

我怀疑会有一个非常简单的方法。最终,你需要

  • 枚举所有用户(或其子集)
  • 迭代生成的用户列表
  • 将每个用户的数据导出到VCard
  • 对于搜索和迭代部分,您可以使用
    PrincipalSearcher
    进行搜索:

    // create your domain context
    using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
    {
       // define a "query-by-example" principal - here, we search for a UserPrincipal 
       // this "QBE" user would give you the ability to further limit what you get back
       // as results from the searcher
       UserPrincipal qbeUser = new UserPrincipal(ctx);
    
       // create your principal searcher passing in the QBE principal    
       PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
    
       // find all matches
       foreach(var found in srch.FindAll())
       {
           UserPrincipal foundUser = found as UserPrincipal;
    
           if(foundUser != null)
           {
              ExportToVCard(foundUser);
           }
       }
    }
    
    现在只需创建
    ExportToVCard
    函数:-)请参阅以获取帮助


    如果您还没有-请阅读MSDN文章,这篇文章很好地展示了如何最好地利用
    System.DirectoryServices.AccountManagement
    中的新功能。或者查看名称空间。

    如果您只需要数据本身,我将查看Softerra的免费LDAP浏览器

    为目录服务器设置配置文件-在浏览器中连接后,您将看到初始设置期间提供的BaseDN的默认架构。在服务器图标上,右键单击,然后点击“导出数据”

    导出向导将引导您完成大部分过程,但重要的部分是步骤3。如果要查找所有用户,只需将搜索筛选器设置为
    (objectClass=user)
    ,确保搜索范围为子树,然后编辑要返回的属性


    您必须将结果处理到vcard中,但这是获取所需所有用户和属性的最简单\最快的方法。

    如果您使用Java,可以使用“ez vcard”创建vcard文件(免责声明:我是作者;):