简体   繁体   English

更新Active Directory用户登录名域

[英]Updating Active Directory User Logon Name Domain

Currently working on automating creation of Active Directory users, but I cannot figure out how to update the field indicated in the linked image. 目前正在致力于自动创建Active Directory用户,但是我不知道如何更新链接图像中指示的字段。 (I can't attach images because I have fewer than 10 posts) image (我不能附加图像,因为我有少于10个) 图像

I can update the user logon name by (userprincipal being an instance of the userprincipal object set to the appropriate user): 我可以通过以下方式更新用户登录名(userprincipal是设置为适当用户的userprincipal对象的实例):

userPrincipal.UserPrincipalName = logonName

and I can update other similar user properties such as job title by (user location being an instance of directoryentry that points to the directory location of the user): 并且我可以通过以下方式更新其他类似的用户属性,例如职务(用户位置是指向用户目录位置的directoryentry的实例):

(userLocation.Properties["title"]).Value = title;

But no matter what I try and adjust, I haven't been able to figure out how to update that particular field. 但是,无论我尝试进行什么调整,我都无法弄清楚如何更新该特定字段。 Any help is greatly appreciated! 任何帮助是极大的赞赏!

You must know the property name before you can set it. 必须先知道属性名称,然后才能进行设置。 there can be 100s and 100s of properties in the active directory some being set from the user interface and some being set from somewhere else, whatever you can check for the properties name by doing the following 活动目录中可能有100到100多个属性,其中一些是在用户界面中设置的,而另一些是在其他地方设置的,无论您通过执行以下操作来检查属性名称

DirectoryEntry directoryEntry = new DirectoryEntry(ConnectionString, ProviderUserName, ProviderPassword, AuthenticationTypes.Secure);
 /******************************/

 DirectorySearcher search = new DirectorySearcher(directoryEntry);
 search.Filter = "(&(objectClass=user)(sAMAccountName=" + username + "))";
 search.CacheResults = false;

 SearchResultCollection allResults = search.FindAll();
 StringBuilder sb = new StringBuilder();

 foreach (SearchResult searchResult in allResults)
 {
     foreach (string propName in searchResult.Properties.PropertyNames)
     {
         ResultPropertyValueCollection valueCollection = searchResult.Properties[propName];
         foreach (Object propertyValue in valueCollection)
         {
             sb.AppendLine(string.Format("property:{0}, value{1}<br />", propName, propertyValue));
         }
     }
 }

 return sb.ToString();

this will result in all the active directory for some user you provide 这将导致您提供的某些用户的所有活动目录

after that you will be able to set all the properties that you want because you have the property name which is available for the user 之后,您将能够设置所需的所有属性,因为您拥有可供用户使用的属性名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM