关于Active Directory中用户的OU和组属性修改的问题?
1.修改用户的OU是否合理?2.通过C#操作Active Directory时,修改用户的OU的代码如何编写呢?
感谢。 --------------------编程问答-------------------- using System;
using System.DirectoryServices;
namespace ADAM_Examples
{
class CreateOU
{
/// <summary>
/// Create ADAM Organizational Unit.
/// </summary>
[STAThread]
static void Main()
{
DirectoryEntry objADAM; // Binding object.
DirectoryEntry objOU; // Organizational unit.
string strDescription; // Description of OU.
string strOU; // Organiztional unit.
string strPath; // Binding path.
// Construct the binding string.
strPath = "LDAP://localhost:389/O=Fabrikam,C=US";
Console.WriteLine("Bind to: {0}", strPath);
// Get ADAM object.
try
{
objADAM = new DirectoryEntry(strPath);
objADAM.RefreshCache();
}
catch (Exception e)
{
Console.WriteLine("Error: Bind failed.");
Console.WriteLine(" {0}", e.Message);
return;
}
// Specify Organizational Unit.
strOU = "OU=TestOU";
strDescription = "ADAM Test Organizational Unit";
Console.WriteLine("Create: {0}", strOU);
// Create Organizational Unit.
try
{
objOU = objADAM.Children.Add(strOU,
"OrganizationalUnit");
objOU.Properties["description"].Add(strDescription);
objOU.CommitChanges();
}
catch (Exception e)
{
Console.WriteLine("Error: Create failed.");
Console.WriteLine(" {0}", e.Message);
return;
}
// Output Organizational Unit attributes.
Console.WriteLine("Success: Create succeeded.");
Console.WriteLine("Name: {0}", objOU.Name);
Console.WriteLine(" {0}",
objOU.Properties["description"].Value);
return;
}
}
}
--------------------编程问答-------------------- 从英文网站上已经找到解决方案:
/// <summary>
/// Moves a User Account to a New OU Path
/// </summary>
/// <param name="oDE">Directory Entry Object of the User to Move</param>
/// <param name="sNewOUPath">The New Path</param>
public void MoveUserAccount(DirectoryEntry oDE, string sNewOUPath)
{
DirectoryEntry myNewPath = null;
//Define the new Path
myNewPath = new DirectoryEntry("LDAP://" + sADServer + "/" + sNewOUPath, sADUser, sADPassword, AuthenticationTypes.Secure);
oDE.MoveTo(myNewPath);
oDE.CommitChanges();
oDE.Close();
}
补充:.NET技术 , C#