Update managers name in active directory?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lairpr74
    New Member
    • Nov 2007
    • 3

    Update managers name in active directory?

    I am trying to update the managers name in active directory with an application I got that updates active directory.

    I been strugling with this for a few weeks now and couldn't find the best way to update the managers name.

    I got a datareader that returns all the employees from the database then a method checks each one of the records and compares them in AD and them commits the changes to the users information.

    This is what I have try so far:

    This is one updates the other properties except the managers name:
    Code:
    using (DirectoryEntry manager = new DirectoryEntry(GetDirectoryEntry()))
                    using (DirectoryEntry minion = new DirectoryEntry(GetDirectoryEntry())) {
                      minion.Properties["manager"].Value =
                          manager.Properties["distinguishedName"].Value.ToString();
                    }
    Error: The value provided for adsObject does not implement IADs.

    With this is one:
    Code:
    if (oEmployee.Manager != String.Empty) {
                      dentry.Properties["manager"].Value = "CN=oEmployee.Manager,DC=domain, DC=net";
    Error: System.Director yServices.Direc toryServicesCOM Exception (0x8007202F): A constraint violation occurred.(Excep tion from HRESULT: 0x8007202F)

    And with this one:
    Code:
    if (oEmployee.Manager != String.Empty) {
                      dentry.Properties["manager"].Value = oEmployee.Manager;
    Error: System.Director yServices.Direc toryServicesCOM Exception (0x8007202F): A constraint violation occurred.(Excep tion from HRESULT: 0x8007202F)



    This is my code:

    Code:
        public void ModifyUsers(SortedList<string , clsEmployee> colEmployee) {
          clsEmployee oEmployee;
          DirectoryEntry dentry;
          string empId;
         
          DirectoryEntry de = GetDirectoryEntry();
          DirectorySearcher dirsearcher = new DirectorySearcher(de);
          dirsearcher.PageSize = 1000;
    
          dirsearcher.Filter = "(&(objectCategory=person)(objectClass=user))";
          SearchResultCollection dsCol = dirsearcher.FindAll();
    
          foreach (SearchResult restEnt in dsCol) {
            dentry = restEnt.GetDirectoryEntry();
    
            if (dentry.Properties["employeeId"] != null) {
              if (dentry.Properties["employeeId"].Value != null) {
                empId = dentry.Properties["employeeId"].Value.ToString();
                oEmployee = new clsEmployee();
                try {
                  oEmployee = colEmployee[empId];
                }
                catch {
                  //do nothing
                }
                if (!oEmployee.empId.Equals(string.Empty)) {            
                 
                  //Update the information
                  try {
                    if (oEmployee.Pager != String.Empty) {
                      dentry.Properties["pager"].Value = oEmployee.Pager;
                    }
                    if (oEmployee.TelephoneNumber != String.Empty) {
                      dentry.Properties["telephoneNumber"].Value = oEmployee.TelephoneNumber;
                    }
                    if (oEmployee.HomePhone != String.Empty) {
                      dentry.Properties["homePhone"].Value = oEmployee.HomePhone;
                    }
                    if (oEmployee.Mobile != String.Empty) {
                      dentry.Properties["mobile"].Value = oEmployee.Mobile;
                    }
                    if (oEmployee.Nextel != String.Empty) {
                      dentry.Properties["ipphone"].Value = oEmployee.Nextel;
                    }
                    if (oEmployee.RadioId != String.Empty) {
                      dentry.Properties["otherIpPhone"].Value = oEmployee.RadioId;
                    }
                    if (oEmployee.Department != String.Empty) {
                      dentry.Properties["department"].Value = oEmployee.Department;
                    }
                    if (oEmployee.Manager != String.Empty) {
                      dentry.Properties["manager"].Value = oEmployee.Manager;
                    }
                    using (DirectoryEntry entryManager = new DirectoryEntry(GetDirectoryEntry()))
                    using (DirectoryEntry dirent = new DirectoryEntry(GetDirectoryEntry())) {
                      dirent.Properties["manager"].Value =
                          entryManager.Properties["manager"].Value = oEmployee.Manager;
                    }
                    //Update managers name
                    //if (oEmployee.Manager != String.Empty) {
                    //  dentry.Properties["distinguishedName"].Value = oEmployee.Manager;
                    //}
                  }
                  catch (Exception e) {
                    //For debugging
                    Console.WriteLine(e.Message);
                  }
                  dentry.CommitChanges();
                  dentry.Close();
                }
              }
            }
          }
    Any ideas of how I can update the manager name?

    Thanks.
    Last edited by Curtis Rutland; Oct 16 '08, 07:05 PM. Reason: added code tags
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • lairpr74
      New Member
      • Nov 2007
      • 3

      #3
      Originally posted by insertAlias
      Please enclose your posted code in [code] tags (See How to Ask a Question).

      This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

      Please use [code] tags in future.

      MODERATOR
      Sorry, I forgot. I'll make sure to include them next time.

      Thanks.

      Comment

      Working...