创建在Active Directory用户:连接到系统的设备无法正常工作连接到、无法正常、用户、设备

2023-09-08 12:16:16 作者:路边野花请别乱采

考虑这个code试图创建一个Active Directory帐户。它在这里产生的异常有一定的数据集。目前还不清楚现在是什么导致了异常。

Consider this code attempting to create an Active Directory account. It's generating an exception here with a certain set of data. It's not clear right now what's causing the exception.

 var user = new UserPrincipal(someValidUserContext,
                              ".x-xyz-t-FooFooBarTest", "somePwd", true);

 user.UserPrincipalName = ".x-xyz-t-FooFooBarTest@foobarbatbaz.net";
 user.SamAccountName = ".x-xyz-t-FooFooBarTest";         
 user.DisplayName = "Some String 16 chars long";
 user.Name =  "Some String 16 chars long";
 user.Description = "Foo BarBaz 12 more characters";
 user.AccountExpirationDate = someDateInFuture;
 user.UserCannotChangePassword = true;
 user.Save();

 // exception thrown on Save(): 
 // A device attached to the system is not functioning

PrincipalOperationException是未处理由用户code:   连接到系统的设备无法正常工作

PrincipalOperationException was unhandled by user code: A device attached to the system is not functioning

是什么导致这个例外,你怎么能解决呢?

What's causing this exception, and how can you work around it?

推荐答案

sAMAccountName属性必须少于20个字符。

The sAMAccountName attribute must be less than 20 characters.