title: Add enabled Computer to Active Directory OU
body: <p>I am trying to programmatically add a computer to the Active Directory of my company.<br>
  I was searching the internet for so long now, but i couldn't find a solution.</p>
  
  <p>My code:</p>
  
  <pre><code>DirectoryEntry dirEntry = new DirectoryEntry("LDAP://OU=ou2example,OU=ou1example,DC=site,DC=company,DC=com");
  dirEntry.Username = "username";
  dirEntry.Password = "password";
  DirectoryEntry newComputer = dirEntry.Children.Add("CN=" + ComputerName, "computer");
  newComputer.CommitChanges();
  </code></pre>
  
  <p>My problem:</p>
  
  <p>The computer is added to the Active Directory. But it is flagged as disabled.</p>
  
  <p><img src="https://i.stack.imgur.com/TJuin.png" alt="enter image description here"></p>
  
  <p>I tried to following to enable the computer:</p>
  
  <pre><code>newComputer.Properties["userAccountControl"].Value = 0x200;
  </code></pre>
  
  <p>But I get an DirectoryServicesCOMException --> The server can not complete the request.</p>
  
  <p>or</p>
  
  <pre><code>newComputer.Properties["Enabled"].Value = true;
  </code></pre>
  
  <p>But I get an DirectoryServicesCOMException --> The requested operation does not satisfy at least one constraint that is for this object class condition.</p>
  
  <p>Please note that the exceptions are translated from german to english!</p>
  
  <p>Thanks for helping!</p>