473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. using (DirectoryEntry manager = new DirectoryEntry(GetDirectoryEntry()))
  2.                 using (DirectoryEntry minion = new DirectoryEntry(GetDirectoryEntry())) {
  3.                   minion.Properties["manager"].Value =
  4.                       manager.Properties["distinguishedName"].Value.ToString();
  5.                 }
Error: The value provided for adsObject does not implement IADs.

With this is one:
Expand|Select|Wrap|Line Numbers
  1. if (oEmployee.Manager != String.Empty) {
  2.                   dentry.Properties["manager"].Value = "CN=oEmployee.Manager,DC=domain, DC=net";
Error: System.DirectoryServices.DirectoryServicesCOMExcep tion (0x8007202F): A constraint violation occurred.(Exception from HRESULT: 0x8007202F)

And with this one:
Expand|Select|Wrap|Line Numbers
  1. if (oEmployee.Manager != String.Empty) {
  2.                   dentry.Properties["manager"].Value = oEmployee.Manager;
Error: System.DirectoryServices.DirectoryServicesCOMExcep tion (0x8007202F): A constraint violation occurred.(Exception from HRESULT: 0x8007202F)



This is my code:

Expand|Select|Wrap|Line Numbers
  1.     public void ModifyUsers(SortedList<string , clsEmployee> colEmployee) {
  2.       clsEmployee oEmployee;
  3.       DirectoryEntry dentry;
  4.       string empId;
  5.  
  6.       DirectoryEntry de = GetDirectoryEntry();
  7.       DirectorySearcher dirsearcher = new DirectorySearcher(de);
  8.       dirsearcher.PageSize = 1000;
  9.  
  10.       dirsearcher.Filter = "(&(objectCategory=person)(objectClass=user))";
  11.       SearchResultCollection dsCol = dirsearcher.FindAll();
  12.  
  13.       foreach (SearchResult restEnt in dsCol) {
  14.         dentry = restEnt.GetDirectoryEntry();
  15.  
  16.         if (dentry.Properties["employeeId"] != null) {
  17.           if (dentry.Properties["employeeId"].Value != null) {
  18.             empId = dentry.Properties["employeeId"].Value.ToString();
  19.             oEmployee = new clsEmployee();
  20.             try {
  21.               oEmployee = colEmployee[empId];
  22.             }
  23.             catch {
  24.               //do nothing
  25.             }
  26.             if (!oEmployee.empId.Equals(string.Empty)) {            
  27.  
  28.               //Update the information
  29.               try {
  30.                 if (oEmployee.Pager != String.Empty) {
  31.                   dentry.Properties["pager"].Value = oEmployee.Pager;
  32.                 }
  33.                 if (oEmployee.TelephoneNumber != String.Empty) {
  34.                   dentry.Properties["telephoneNumber"].Value = oEmployee.TelephoneNumber;
  35.                 }
  36.                 if (oEmployee.HomePhone != String.Empty) {
  37.                   dentry.Properties["homePhone"].Value = oEmployee.HomePhone;
  38.                 }
  39.                 if (oEmployee.Mobile != String.Empty) {
  40.                   dentry.Properties["mobile"].Value = oEmployee.Mobile;
  41.                 }
  42.                 if (oEmployee.Nextel != String.Empty) {
  43.                   dentry.Properties["ipphone"].Value = oEmployee.Nextel;
  44.                 }
  45.                 if (oEmployee.RadioId != String.Empty) {
  46.                   dentry.Properties["otherIpPhone"].Value = oEmployee.RadioId;
  47.                 }
  48.                 if (oEmployee.Department != String.Empty) {
  49.                   dentry.Properties["department"].Value = oEmployee.Department;
  50.                 }
  51.                 if (oEmployee.Manager != String.Empty) {
  52.                   dentry.Properties["manager"].Value = oEmployee.Manager;
  53.                 }
  54.                 using (DirectoryEntry entryManager = new DirectoryEntry(GetDirectoryEntry()))
  55.                 using (DirectoryEntry dirent = new DirectoryEntry(GetDirectoryEntry())) {
  56.                   dirent.Properties["manager"].Value =
  57.                       entryManager.Properties["manager"].Value = oEmployee.Manager;
  58.                 }
  59.                 //Update managers name
  60.                 //if (oEmployee.Manager != String.Empty) {
  61.                 //  dentry.Properties["distinguishedName"].Value = oEmployee.Manager;
  62.                 //}
  63.               }
  64.               catch (Exception e) {
  65.                 //For debugging
  66.                 Console.WriteLine(e.Message);
  67.               }
  68.               dentry.CommitChanges();
  69.               dentry.Close();
  70.             }
  71.           }
  72.         }
  73.       }
  74.  
Any ideas of how I can update the manager name?

Thanks.
Oct 16 '08 #1
2 2663
Curtis Rutland
3,256 Expert 2GB
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
Oct 16 '08 #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
Sorry, I forgot. I'll make sure to include them next time.

Thanks.
Oct 16 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Pam Ammond | last post by:
I need the code to update the database when Save is clicked and a text field has changed. This should be very easy since I used Microsoft's wizards for the OleDBAdapter and OleDBConnection, and...
0
by: Kooki | last post by:
Hi, I am developing a small programme to add ACTIVE DIRECTORY users to another server. everything works fine .. I get the users from AD using LDAP but while adding users I need to get the user...
0
by: Kooki | last post by:
Hi, I am developing a small programme to add ACTIVE DIRECTORY users to another server. everything works fine .. I get the users from AD using LDAP but while adding users I need to get the user...
18
by: Arthur | last post by:
Hi All, I would like to get the name of the user given their networkID, is this something Active Directory would be useful for?(For intranet users) If so, can you please point me to some sample...
2
by: Paul Hadfield | last post by:
All, Can anyone help with an example of how to use the System.DirectoryServices name space? I've found examples on Google in C# but I've had no success trying to use them. Basically, I...
0
by: =?Utf-8?B?SmVhbmluZQ==?= | last post by:
Hi, can anyone tell me how I can update the publicDelegates active directory property using vb.net 2005 and System.DirectoryServices. I understand the publicDelegates property to be where 'send of...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
4
by: hapnendad | last post by:
In the question statement below Field names are in and variables are in (). All fields referenced are in what I have named the ‘PAR’ Table. Using MS Access 2003, I am working on a project...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.