title: How to get domain sid from domain dns name?
body: <p>I have the dns name of an Active Directory domain and I would like to get the domain sid for this domain. How can I do this?</p>
  
  <p>I already have the following:</p>
  
  <pre><code>var domainContext =
      new DirectoryContext(DirectoryContextType.Domain, domainDnsName);
  var domain = Domain.GetDomain(domainContext);
  var dc = domain.DomainControllers.OfType&lt;DomainController&gt;().FirstOrDefault();
  </code></pre>
  
  <p>But I'm a little stuck where to go from here (or maybe I'm following the wrong route).</p>