title: How can I find what Organizational Units a computer is part of? ( Active Directory C# )
body: <p>I want to find the most specific OU my computer belongs to in C#.
  I have code that will get the information I need, but it doesn't feel robust and it would require complicated parsing.
  Are there better alternatives?  Thoughts?  Any help is appreciated!</p>
  
  <p>Really what I want is an equivilent to the command prompt command:</p>
  
  <pre><code>dsquery computer -name COMP-HERE
  </code></pre>
  
  <p>But I need it in C#, which is proving to be problematic.</p>
  
  <pre><code>DirectorySearcher d = new DirectorySearcher("CN=COMP-HERE");
  d.PropertiesToLoad.Add("adspath");
  SearchResultCollection results = d.FindAll();
  foreach (SearchResult searchResult in results) {
      foreach (string propertyKey in searchResult.Properties.PropertyNames) {
          ResultPropertyValueCollection valueCollection = searchResult.Properties[propertyKey];
          foreach (Object propertyValue in valueCollection) {
              Console.WriteLine(
              "{0}:{1}",
              propertyKey,
              propertyValue.ToString());
          }
      }
  }
  Console.ReadLine();
  </code></pre>