将AD用户从OU移动到另一个OU

时间:2016-03-10 07:06:33

标签: c# active-directory

我想使用C#将活动目录用户从一个组织单位移动到另一个组织单位。

我在下面提到了链接

  1. http://forums.asp.net/t/932664.aspx?Moving+an+AD+user+from+an+OU+to+another+OU
  2. http://www.nullskull.com/q/10279930/to-move-a-user-from-one-ou-to-another-ou.aspx
  3. 并尝试下面的代码,但它会抛出错误

        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
            {
                var cell2 = MostLikedTVCscnd()//custom Cell for 2nd Table
                var cell1 = MostLikedTVC()//custom Cell for 1st Table
    
                if tableView == tableViewCol1
                {
                    let cell = tableViewCol1.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as! MostLikedTVC
                    cell.imageCol1.image = imageArr1[indexPath.row] as? UIImage
                    cell.aboutLblCol1.text = labelArr1[indexPath.row] as? String//dynamic increasing label
                    cell1=cell
                }
                else if tableView == tableViewCol2
                {
                    let cell = tableViewCol2.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as! MostLikedTVCscnd
                    cell.imageCol2.image = imageArr2[indexPath.row] as? UIImage
                    cell.aboutLblCol2.text = labelArr2[indexPath.row] as? String
                    cell2 = cell
                }
    
    //changing the height constraint of table's to make the table view non scrollable
               tableView1HghtCnstrnt.constant = tableViewCol1.contentSize.height
               tableView2HghtCnstrnt.constant = tableViewCol2.contentSize.height
    
         //comparing the content size of table's to check which table is the tallest & adjust the height of the main ScrollView's content       
                if tableViewCol1.contentSize.height>tableViewCol2.contentSize.height
                {
                    mainViewHghtCnstrnt.constant = tableViewCol1.contentSize.height+35//mainViewHghtCnstrnt :- mainScrollView's content height constraint & 35 is the padding
                }
                else if tableViewCol1.contentSize.height<tableViewCol2.contentSize.height
                {
                    mainViewHghtCnstrnt.constant = tableViewCol2.contentSize.height+35
                }
                else if tableViewCol1.contentSize.height==tableViewCol2.contentSize.height
                {
                    mainViewHghtCnstrnt.constant = tableViewCol2.contentSize.height+35
                }
    
    //returning the cell
                if tableView == tableViewCol1
                {
                    return cell1
    
                }
                else
                {
                    return cell2
    
                }
    
            }
    
        }
    

    以上代码抛出错误

    DirectoryEntry eLocation = new DirectoryEntry("LDAP://CN=Test User,OU=Users,OU=Development,DC=domain,DC=com");
    DirectoryEntry nLocation = new DirectoryEntry("LDAP://OU=Users,OU=QC,DC=domain,DC=com");
    eLocation.MoveTo(nLocation);
    

2 个答案:

答案 0 :(得分:4)

我已经通过了如下的用户凭证,它就像一个魅力。

DirectoryEntry eLocation = new DirectoryEntry("LDAP://CN=Test User,OU=Users,OU=Development,DC=domain,DC=com", "domain\admin", "password");
DirectoryEntry nLocation = new DirectoryEntry("LDAP://OU=Users,OU=QC,DC=domain,DC=com", "domain\admin", "password");
eLocation.MoveTo(nLocation);
nLocation.Close();
eLocation.Close();

答案 1 :(得分:0)

您不需要任何凭据即可通过 我做了以下

DirectoryEntry oDE =新的DirectoryEntry(LDAP://“ +” CN =“ xxx OU = xxxx,DC = xxxxxxx,DC = xxx”); DirectoryEntry de = new DirectoryEntry(“ LDAP://” +“ OU = xxxx,DC = xxxxxxx,DC = xxx”); oDE.MoveTo(de);