Hi All
I am using windows 2008 R2 Server and trying to Add a user in active directory .
I am using the code below to add user in Active Directory
public static void AddUser(ADUser adUser){ if (_logger.IsDebugEnabled) _logger.Debug("ADHelper.cs: Enter AddUser");
// Local variables DirectoryEntry oDE = null; DirectoryEntry oDENewUser = null; DirectoryEntries oDEs = null;try{oDE = GetDirectoryEntry(GetADPath(adUser.UserType));// 1. Create user accountoDEs = oDE.Children;oDENewUser = oDEs.Add("CN=" + adUser.UserName, "user");// 2. Set propertiesSetProperty(oDENewUser, Constants.ADAttributes.givenName, adUser.FirstName);SetProperty(oDENewUser, Constants.ADAttributes.initials, adUser.MiddleInitial);SetProperty(oDENewUser, Constants.ADAttributes.sn, adUser.LastName);SetProperty(oDENewUser, Constants.ADAttributes.mail, adUser.Email);SetProperty(oDENewUser, Constants.ADAttributes.sAMAccountName, adUser.UserName);SetProperty(oDENewUser, Constants.ADAttributes.ChallengeQuestion, adUser.PasswordChallengeQuestion);SetProperty(oDENewUser, Constants.ADAttributes.ChallengeAnswer, adUser.PasswordChallengeAnswer);SetProperty(oDENewUser, Constants.ADAttributes.ChallengeQuestion2, adUser.PasswordChallengeQuestion2);SetProperty(oDENewUser, Constants.ADAttributes.ChallengeAnswer2, adUser.PasswordChallengeAnswer2);// Sharepoint changesif (adUser.CompanyGroupSupplier != string.Empty){SetProperty(oDENewUser, Constants.ADAttributes.CompanyGroupSupplier, adUser.CompanyGroupSupplier);}if (adUser.PersonalGroupAddress != string.Empty){SetProperty(oDENewUser, Constants.ADAttributes.PersonalGroupAddress, adUser.PersonalGroupAddress);}if (adUser.PersonalGroupPhone != string.Empty){SetProperty(oDENewUser, Constants.ADAttributes.PersonalGroupPhone, adUser.PersonalGroupPhone);}// Sharepoint changesoDENewUser.CommitChanges();// 3. Set passwordSetPassword(oDENewUser.Path, adUser.Password);// 4. Enable accountEnableAccount(oDENewUser);oDENewUser.Close();oDE.Close();if (_logger.IsDebugEnabled)_logger.Debug("ADHelper.cs: Exit AddUser");}catch (ApplicationException appex){if (_logger.IsErrorEnabled)_logger.Error("ADHelper.cs: Exception occurred in AddUser. Message: ", appex);throw appex;}catch (Exception ex){if (_logger.IsErrorEnabled)_logger.Error("ADHelper.cs: Exception occurred in AddUser. Message: ", ex);throw ex;}finally{if (oDENewUser != null){oDENewUser.Dispose();oDENewUser = null;}if (oDEs != null){oDEs = null;}if (oDE != null){oDE.Dispose();oDE = null;}}}
Please any one can suggest me how can increase sAMAccountName length in Active Directory around 30 characters in length.
Thanks in Advance
I am able to save user ID of length less than 20 Characters.But when I am trying to increase this value to 30 characters then I am getting the error.
"System.DirectoryServices.DirectoryServicesCOMException (0x8007001F): A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F)"
This error when I searched on net give me various links saying that:
(a) Please verify if the issue is caused by the length of sAMAccountName
(b) The document of SAM-Account-Name also indicates that the length of it should be less than 20 characters.