1

Whenever I am trying to save a UserPrincipal to Active Directory and the UserPrincipalName or EmailAddress length is longer than 20 characters the UserPrincipal.Save method will throw the following error:

'System.DirectoryServices.AccountManagement.PrincipalOperationException' A device attached to the system is not functioning active

How to save an emailaddress with a length longer than 20 characters?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
H3AP
  • 1,058
  • 1
  • 10
  • 16
  • 1
    can you show the actual code where you are using `PrincipalContext` object I use this all the time and have never run into any issues saving email address back to AD.. also do you have a system admin whom manages your AD – MethodMan Dec 21 '14 at 20:04
  • The PrincipalContext and UserPrincipal codes are good. I can save without a hitch, except when user more than 20 characters in a emailaddress. I have the AD in a vm. It is a 2008 server with the 2003 functional level increased too 2008 r2. – H3AP Dec 21 '14 at 20:14
  • perhaps you need to check there then... what is the default length setup as also have your tried calling the `Trim()` method perhaps it's something as simple as that if there are extra spaces in the email at the end of the email string for example are you familiar with Provisioning..? you need to set the length of the email to be larger than 20 and no greater than 255 characters http://technet.microsoft.com/en-us/library/hh852478.aspx – MethodMan Dec 21 '14 at 20:16
  • at this point the values are hardcoded so i am totally sure they are correct. However i found the following question: http://stackoverflow.com/questions/3095510/creating-a-user-in-active-directory-a-device-attached-to-the-system-is-not-func I just have the same problem but then for the emailaddress field – H3AP Dec 21 '14 at 20:20
  • you know I can't tell what is right or wrong since you are not showing any code.. if the values are hard coded then perhaps you should hardcode everything except the email address to be 20 chars or less.. good luck – MethodMan Dec 21 '14 at 20:22
  • If I recall correctly, the `samAccountName` on certain types of AD objects was limited to 20 characters. Could that be the problem? You **really** need to **SHOW US** your code!! – marc_s Dec 21 '14 at 20:54
  • Sorry for being a bit to stubborn and not posting my code. It was getting a bit late i think. However i did found the answer which i will add now. Thanks for the help. – H3AP Dec 22 '14 at 09:51
  • @MethodMan https://technet.microsoft.com/en-us/library/hh852478.aspx not found – Kiquenet Jun 13 '18 at 10:50

1 Answers1

3

The UserPrincipal.Name would be copied to the UserPrincipal.SamAccountName whenever no SamAccountName was specified.

When the UserPrincipal.Name was longer than 20 characters, this would ofcourse throw an exception. In this case a weird one. To fix this problem, i had to set the SamAccountName manually before saving to something less than 20 characters.

H3AP
  • 1,058
  • 1
  • 10
  • 16
  • ***sAMAccountName maxlength*** https://stackoverflow.com/questions/3095510/creating-a-user-in-active-directory-a-device-attached-to-the-system-is-not-func – Kiquenet Jun 13 '18 at 10:49