執行下面的代碼,看看是所有屬性的提供您的廣告。還有就是你可能有一個變化拼錯的關鍵或鑰匙不在您的廣告存在的所有屬性
DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
try
{
foreach (string property in resEnt.Properties.PropertyNames)
{
string value = resEnt.Properties[property][0].ToString();
Console.WriteLine(property + ":" + value);
}
}
catch (Exception)
{ }
}
名單在我的Windows Server 2008 R2 AD
objectClass=top;person;organizationalPerson;user
cn=x1
sn=LastName
c=PL
l=City
st=State
title=Job title
description=Description
postalCode=Zip
postOfficeBox=POBox
physicalDeliveryOfficeName=Office
telephoneNumber=123456779
givenName=FirstName
distinguishedName=CN=x1,CN=Users,DC=helpdesk,DC=wat,DC=edu
instanceType=4
whenCreated=2012-11-27 21:37:37
whenChanged=2012-12-11 21:33:51
displayName=DisplayName
uSNCreated=System.__ComObject
uSNChanged=System.__ComObject
co=Poland
department=Department
company=Company
streetAddress=Street
name=x1
objectGUID=System.Byte[]
userAccountControl=66048
badPwdCount=0
codePage=0
countryCode=616
badPasswordTime=System.__ComObject
lastLogoff=System.__ComObject
lastLogon=System.__ComObject
pwdLastSet=System.__ComObject
primaryGroupID=513
objectSid=System.Byte[]
accountExpires=System.__ComObject
logonCount=1
sAMAccountName=x1
sAMAccountType=805306368
[email protected]
objectCategory=CN=Person,CN=Schema,CN=Configuration,DC=helpdesk,DC=wat,DC=edu
dSCorePropagationData=1601-01-01 00:00:00
lastLogonTimestamp=System.__ComObject
[email protected]
homePhone=1236456654654659
mobile=800800800
nTSecurityDescriptor=System.__ComObject
來源
2015-04-24 08:03:54
Rad
調試它。當你得到一些用戶檢查UserPrincipal的所有屬性。如果有任何屬性被填入像GivenName或其他東西 - 比它被讀取,所以如果某些屬性爲空 - 那麼它真的是nul – MajkeloDev