itedstrom
asked on
Updating the Active Directory manager field via C#
I am updating numerous fields in Active Directory, successfully, via C# and pulling data from a SQL database:
DirectoryEntry deAD = new DirectoryEntry("LDAP://AD1 /CN=" + empCommonName + ",OU=EI Users,DC=ei,DC=mycompanyna me,DC=com" );
//output the data to the screen so that we can at least see the order of updates
Console.WriteLine("empComm onName value = " + empCommonName + " manager name = " + ManagerNm + "ADCommonnamevalue = " + deAD.Properties["CN"].Valu e);
if (empCommonName != deAD.Properties["CN"].Valu e)
{if (PHextension != null && PHextension.Length>0){deAD .Propertie s["telepho neNumber"] .Value = PHextension;}
if (empDepartment != null && empDepartment.Length>0){de AD.Propert ies["depar tment"].Va lue = empDepartment;}
if (empTitle != null && empTitle.Length>0){deAD.Pr operties[" title"].Va lue = empTitle;}
...etc.
I now need to update the manager field in AD, and I am trying this:
if (ManagerNm != null && ManagerNm.Length>0) {deAD.Properties["manager" ].Value = "CN=" + ManagerNm + ",OU=myCompanyName,dc=DC,d c=com" ;}
I am understanding that I need to pass the inforamtion as above and am receiving the error below:
An unhandled exception of type 'System.Runtime.InteropSer vices.COME xception' occurred in system.directoryservices.d ll
Additional information: A constraint violation occurred.
I know I'm passing the correct "manager" from my SQL database, though I may be struggling with a simple syntax issue. Any help would be greatly appreciated.
DirectoryEntry deAD = new DirectoryEntry("LDAP://AD1
//output the data to the screen so that we can at least see the order of updates
Console.WriteLine("empComm
if (empCommonName != deAD.Properties["CN"].Valu
{if (PHextension != null && PHextension.Length>0){deAD
if (empDepartment != null && empDepartment.Length>0){de
if (empTitle != null && empTitle.Length>0){deAD.Pr
...etc.
I now need to update the manager field in AD, and I am trying this:
if (ManagerNm != null && ManagerNm.Length>0) {deAD.Properties["manager"
I am understanding that I need to pass the inforamtion as above and am receiving the error below:
An unhandled exception of type 'System.Runtime.InteropSer
Additional information: A constraint violation occurred.
I know I'm passing the correct "manager" from my SQL database, though I may be struggling with a simple syntax issue. Any help would be greatly appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
CN=" + ManagerNm + ",OU=myCompanyName,dc=DC,d
to make this update in the first place. Thanks!