Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The attribute name is 'location'. As with all AD properties, you won't see it on a search result object if it doesn't have a value. I've fiddled with your code so that it would just work on my machine.</p> <p>If you're only retrieving data and not planning to make any changes you don't need to call GetDirectoryEntry (which will impose another round-trip to the servers). Note the slight difference in syntax:</p> <pre><code>var rootDSE = new DirectoryEntry("LDAP://RootDSE"); var defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString(); var domainRootADsPath = String.Format("LDAP://{0}", defaultNamingContext); var searchRoot = new DirectoryEntry(domainRootADsPath); var filter = "(&amp;(objectCategory=computer)(name=" + computerName + "))"; var directorySearch = new DirectorySearcher(searchRoot, filter); var directorySearchResult = directorySearch.FindOne(); if (null != directorySearchResult) { Console.WriteLine(directorySearchResult.Properties["cn"][0].ToString()); if (directorySearchResult.Properties["location"].Count &gt; 0) { Console.WriteLine(directorySearchResult.Properties["location"][0].ToString()); } //It's not necessary to run GetDirectoryEntry unless you want to make a change DirectoryEntry deComp = directorySearchResult.GetDirectoryEntry(); Console.WriteLine(deComp.Properties["cn"].Value.ToString()); if (deComp.Properties["location"].Value != null) { Console.WriteLine(deComp.Properties["location"].Value.ToString()); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload