Pis*_*ete 1 ssis active-directory
我已经看到了很多从AD中提取数据的帖子,但是我需要更新AD,但找不到我想要的东西。我的公司一直在使用第三方供应商(intelli-desk)来安置部门,经理和电话等。信息多年。AD仅用于创建用户名和分配域访问权限。我们知道有必要使用智能办公桌中的信息将AD更新到AD。我已经建立了一个查询,该查询将AD和智能桌面数据库进行比较,并希望获取该查询的结果,其中sn和namedName匹配并更新AD中的Ext。,Dept。等。我当时以为SSIS软件包可能是最好的方法,因此它可以成为计划的工作,因为我认为我们不会停止使用3rd party软件。是否有人对使用SSIS有任何建议,如果有,您将如何处理。
我最近刚从数据库中完成了类似的任务(插入,更新) Active Directory用户。您可以完成此任务的选项很少:
使用评论中提到的@billinkc等第三方软件。但是,这比利弊更多。它们中的大多数都不具有成本效益,而且,它们在您可以做的事情上受到限制(如果您不购买源代码)。不建议您选择这条路线。
有一种使用SSIS包来完成此任务的方法。此technet 文章解释了如何使用外部源将用户导入到Active Directory。SSIS软件包将使用以VBA或编写的外部脚本C#。C#本文提供的示例是在较旧的.NET库中编写的。它正在使用DirectoryEntry类。使用此类并没有什么问题,但是.NET 3.5Microsoft引入了更高的类System.DirectoryServices.AccountManagement,它使用起来更简单。
使用AccountManagement名称空间自己编写。听起来并不难。
由于您在数据库中拥有所有用户信息,因此可以编写一个stored procedure将返回用户信息的。
这是您要开始的事情。
通过调用从数据库加载用户信息stored procedure。
public static DataTable GetUserInfoByUsername(string username)
{
//call stor proc to return data
//return datatable or custom class that will hold user iformation
}
Run Code Online (Sandbox Code Playgroud)
编写will Create和Updateuser的两个方法。使用from值datatable填充Active Directory中的用户属性。
public static string CreateUser(DataTable dt, string password)
{
//CREATE CONNECTION TO ACTIVE DIRECTORY
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "yourdomain.com"))
{
//CREATE A NEW USERPRINCIPAL OBJECT
using (UserPrincipal principal = new UserPrincipal(ctx))
{
//TODO: you need to populate the below info with values from dt
principal.Enabled = true; //IF NOT ENABLED YOU CAN'T AUTHENTICATE THE USER
principal.UserPrincipalName = username;
principal.Name = "name";
principal.DisplayName = "firstname lastname";
principal.EmailAddress = "email@test.com";
principal.VoiceTelephoneNumber = "12345678910";
principal.GivenName = "firstname";
principal.Surname = "lastname";
principal.SetPassword(password);
try
{
principal.Save();
}
catch(Exception ex)
{
throw;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可以采用类似的方法来更新用户。
public static void UpdateUser(string userName, DataTable dt)
{
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "yourdomain.com"))
{
//you have more than one way to search for a user in AD. Identitype has more choises
using (UserPrincipal principal = UserPrincipal.FindByIdentity(ctx, Identitype.samAccountName, username))
{
if (principal !== null)
//update user properties with data from datatable dt
...
principal.Save();
}
}
}
Run Code Online (Sandbox Code Playgroud)
要记住的东西。默认情况下,UserPrincipal类不会显示每个活动目录属性。获取这些属性的最快方法是使用DirectoryEntry类。您可以调用的GetUnderlyingObject()方法principal。
DirectoryEntry de = (principal.GetUnderlyingObject() as DirectoryEntry);
if (de != null)
{
if (de.Properties.Contains("company"))
string company = de.Properties["company"][0].ToString();
}
Run Code Online (Sandbox Code Playgroud)
如果您想运行某种工作来执行这些操作,只需在调用任何这些方法之前stored procedure让所有用户返回并使用foreach循环即可。
我建议您编写一个Windows服务,并在那里执行所有这些操作。
*注意代码不完整。根据您的需要,您需要修改代码。**
| 归档时间: |
|
| 查看次数: |
2268 次 |
| 最近记录: |