title: Connect to active directory with PrincipalContext
body: <p>Im writtem app that looks for a user in active directory based on there name</p>
  
  <p>When I try to create new PrincipalContext with ContextType.Domain and the domain name as a string, I get the exception  "The server could not be contacted."</p>
  
  <p>So to get the the AD that I did this ...
  Open System by clicking the Start button Picture of the Start button, clicking Control Panel, clicking System and Maintenance, and then clicking System.
  Which I got from <a href="http://windows.microsoft.com/en-gb/windows-vista/find-the-domain-your-computer-is-on" rel="nofollow">http://windows.microsoft.com/en-gb/windows-vista/find-the-domain-your-computer-is-on</a></p>
  
  <p>Which gave me 
  Something.Something (not this, but two strings with a . between them)</p>
  
  <p>So when I run the following code and enter Something.Something as the domain, I get the exception "The server could not be contacted." on the new PrincipalContext(ContextType.Domain, domain);
  I have tried changing the case of the string and the but dont seem to have any luck.</p>
  
  <p>So what should I be using for the domain?</p>
  
  <pre><code>    public static void Main(string[] args)
      {
          try
          {
              Console.WriteLine("Enter Domain, then press enter.");
              string domain = Console.ReadLine();
  
              Console.WriteLine("Enter First Name, then press enter.");
              string userName = Console.ReadLine();
  
              //This is the line that always crashes throws error
              var principalContext = new PrincipalContext(ContextType.Domain, domain);
              var user = UserPrincipal.FindByIdentity(principalContext, userName);
  
              if (user == null)
              {
                  Console.WriteLine("User Not Found");
              }
  
              var groups = user.GetGroups(principalContext);
              var result = new List&lt;string&gt;();
              groups.ToList().ForEach(sr =&gt; result.Add(sr.SamAccountName));
  
              foreach (var item in result)
              {
                  Console.WriteLine(item);
              }
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.Message);
          }
      }
  </code></pre>