在AD中,组织单位中的用户移动,如何实现?
有几个ou,其中一个是离职ou。请帮忙,想实现ou中用户移动,感谢,感谢!.net程序
--------------------编程问答--------------------
顶一个先
--------------------编程问答--------------------
/// <summary>
/// 添加用户到组织
/// </summary>
/// <param name="userName"></param>
/// <param name="GroupName"></param>
public void AddUserToOU(string userName,string GroupName)
{
// "(&(objectClass=organizationalunit) (OU=" + OuName + "))";
DirectoryEntry de = AdHelp.GetDirectoryEntry();
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.Filter = "(&(objectClass=organizationalunit) (OU=" + GroupName + "))"; ;
SearchResultCollection results = deSearch.FindAll();
bool isGroupMember = false;
if (results.Count > 0)
{
DirectoryEntry deUser = de.Children.Find("CN=" + userName, "user");
DirectoryEntry ou = AdHelp.GetDirectoryEntry(results[0].Path);
object members = ou.Invoke("Members", null);
foreach (object member in (IEnumerable)members)
{
DirectoryEntry x = new DirectoryEntry(member);
if (x.Name != deUser.Name)
{
isGroupMember = false;
}
else
{
isGroupMember = true;
break;
}
}
if (!isGroupMember)
{
ou.Invoke("Add", new object[] { deUser.Path.ToString() });
}
ou.Close();
}
return;
}
补充:.NET技术 , C#