public void MoveTo(params string[] OUs)
{
DirectoryEntry node = null;
string container = _connection.Container;
string connString = string.Format("LDAP://{0}/{1}", _connection.Name, container);
node = new DirectoryEntry(connString, _connection.User, _connection.Password);
foreach (string name in OUs.Reverse().Select(i=>"OU=" + i))
{
DirectoryEntry child=null;
try
{
child = node.Children.Find(name, "OrganizationalUnit");
}
catch (DirectoryServicesCOMException)
{
child = node.Children.Add(name, "OrganizationalUnit");
child.CommitChanges();
}
node.Close();
node = child;
}
try
{
if (isNewUser)
{
this.Save();
}
this.directoryEntry.MoveTo(node, this.directoryEntry.Name);
this.directoryEntry.CommitChanges();
}
catch (Exception ex)
{
string msg = String.Format("Error moving user '{0}' to location '{1}': '{2}'", this.DisplayName, node.Name, ex.Message);
Console.WriteLine(msg);
throw new ADException(msg, ex);
}
}