Blog Post

AD Exception: A device attached to the system is not functioning

Friday, August 21, 2015 12:54 PM

Today I have come across beautiful error exception

 

A device attached to the system is not functioning

 

I would like to share How to fix it

 

My code is as follows:

 

try
{
using (var context = new PrincipalContext(ContextType.Domain, domainName, systemUserName, systemPwd))
{
UserPrincipal up = new UserPrincipal(context);
up.SamAccountName = samAccountName;
up.SetPassword("password");
up.ExpirePasswordNow();
up.Save();
}
return true;
}
catch (Exception exception)
{
return false;
}

This is by itself pretty straight forward code

 

Solution

 Turns out that the data I have been passing in have been greater than 20 characters for SamAccountName.

The field SamAccounName has limit 20 characters.