I'm trying to update a set of users in Active Directory from an Excel spreadsheet.
This is how I'm doing it now:
(oRow is a DataRow object)
SearchResult
result = search.FindOne(); if (result != null){
DirectoryEntry user = result.GetDirectoryEntry(); if (user.Properties["employeeNumber"].Value == null)
user.Properties[
"employeeNumber"].Add(HashSSN(oRow["SSN"].ToString())); if (oRow["First_Name"].ToString() != user.Properties["givenName"].ToString())user.Properties[
"givenName"].Value = oRow["First_Name"].ToString(); if(oRow["Last_Name"].ToString() != user.Properties["sn"].ToString())user.Properties[
"sn"].Value = oRow["Last_Name"].ToString(); if (user.Properties["initials"].Value == null)user.Properties[
"initials"].Value = oRow["Middle_Init"].ToString(); if (oRow["Middle_Init"].ToString() != user.Properties["initials"].ToString())user.Properties[
"initials"].Value = oRow["Middle_Init"].ToString(); if (user.Properties["telephoneNumber"].Value == null)user.Properties[
"telephoneNumber"].Value = oRow["Dorm_Ext"].ToString(); if (oRow["Dorm_Ext"].ToString() != user.Properties["telephoneNumber"].ToString())user.Properties[
"telephoneNumber"].Value = oRow["Dorm_Ext"].ToString(); if (HashSSN(oRow["SSN"].ToString()) != user.Properties["employeeNumber"].ToString())user.Properties[
"employeeNumber"].Value = HashSSN(oRow["SSN"].ToString());user.CommitChanges();
}
When I run this code, it throws an exception with the text "Only one type of operation can be performed in a sequence."
How do I fix this

Multiple updates to an Active Directory user in one pass
AlexGadea
Ravengaard