使用C#SSIS从Active Directory加载多行

时间:2017-03-20 20:08:47

标签: c# ssis active-directory

我正忙着将活动目录中的信息加载到我的SSIS脚本中。我有负载部分(我有几个部分到我的项目正常工作,只是没有这个)。我遇到的问题是从Active Directory加载。

我尝试了一些我在网上找到的不同例子。虽然我熟悉编程,但C#不是我选择的语言,因此有点难以弄清楚是什么问题。

我想要做的是使用脚本组件来获取单域Active Directory中的所有用户。我尝试过的脚本有时什么都不返回,但通常只返回一行。

以下是我目前使用的代码。谁能告诉我我做错了什么?

我正在使用最新版本的Visual Studio Community 2015使用C#2015构建SSIS内容来构建脚本组件。

public override void CreateNewOutputRows()
{

   try
   {

    string groupName = "Domain Users";
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "mic.local");

    UserPrincipal qbeUser = new UserPrincipal(ctx);
    //GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, groupName);


    PrincipalSearcher srch = new PrincipalSearcher(qbeUser);


    foreach(UserPrincipal found in srch.FindAll())
    {

    //foreach (Principal found in grp.GetMembers(false))
    //{ 

        //UserPrincipal userFound = found as UserPrincipal;

        MyOutputBuffer.AddRow();
        MyOutputBuffer.LoginName = found.SamAccountName;
        MyOutputBuffer.OfficeLocation = found.GetOfficeLocation();
        MyOutputBuffer.Lastname = found.getLastName();
        MyOutputBuffer.Middlename = found.getMiddleName();
        MyOutputBuffer.Firstname = found.getFirstName();
        MyOutputBuffer.CreatedDate = Convert.ToDateTime(found.GetCreateDate());
        MyOutputBuffer.EmailAddress = found.getEmail();
        MyOutputBuffer.IsDeleted = Convert.ToBoolean(found.GetIsDeleted());

    }

    ctx.Dispose();
}
catch
{
   //
}

0 个答案:

没有答案