SSIS使用Script task处理Active Directory

来源:互联网 发布:unity3d怎么导入模型 编辑:程序博客网 时间:2024/05/24 08:33

SSIS的Script Task有着很大的自由度,可以通过写代码的方式来实现各种各样的需求。

这里以C#代码为例,对AD信息进行操作。


首先需要添加引用System.DirectoryServices

然后修改main方法即可进行下一步操作

/// <summary>        /// This method is called when this script task executes in the control flow.        /// Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.        /// To open Help, press F1.        /// </summary>public void Main(){            try            {                //  get the directory entry root                DirectoryEntry dirEntry = new DirectoryEntry();                dirEntry.Path = "LDAP://CNSRVADC01/DC=CORP,DC=Intra";                DirectoryEntries adUsers = dirEntry.Children;                DirectoryEntry adUser;                //  search users                DirectorySearcher deSearch = new DirectorySearcher();                deSearch.Filter = ("(&(objectClass=User) (objectCategory=Person))");                deSearch.SearchRoot = dirEntry;                SearchResultCollection results = deSearch.FindAll();                for (int i = 0; i < results.Count; i++)                {                    adUser = new DirectoryEntry(results[i].Path);                    //...add code here to handle the AD INFO                 }                Dts.TaskResult = (int)ScriptResults.Success;            }            catch (Exception ex)            {                Dts.TaskResult = (int)ScriptResults.Failure;            }}







0 0
原创粉丝点击