我正在尝试检索计算机名称列表以及它们上次从 Active Directory 登录的日期,并将它们返回到数据表中。获取名称很容易,但是当我尝试添加如下所示的“lastLogon”或“lastLogonTimestamp”时,我为 lastLogonTimestamp 获得的唯一值是“System._ComObject”
public DataTable GetListOfComputers(string domainName)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://DC=" + domainName + ",DC=com");
DirectorySearcher search = new DirectorySearcher(entry);
string query = "(objectclass=computer)";
search.Filter = query;
search.PropertiesToLoad.Add("name");
search.PropertiesToLoad.Add("lastLogonTimestamp");
SearchResultCollection mySearchResultColl = search.FindAll();
DataTable results = new DataTable();
results.Columns.Add("name");
results.Columns.Add("lastLogonTimestamp");
foreach (SearchResult sr in mySearchResultColl)
{
DataRow dr = results.NewRow();
DirectoryEntry de = sr.GetDirectoryEntry();
dr["name"] = de.Properties["Name"].Value;
dr["lastLogonTimestamp"] = de.Properties["lastLogonTimestamp"].Value;
results.Rows.Add(dr);
de.Close();
}
return results;
}
如果我使用 LDP 之类的工具查询 AD,我可以看到该属性存在并且填充了数据。我怎样才能得到这个信息?