title: How can I add a new user to my system's domain using .Net DirectoryServices?
body: <p>I want to write a Console application which will just add a new User to my own machine's Domain using .Net DirectoryServices API and LDAP. </p>
  
  <p>Do I need admin account Password for the DomainController to do this ?</p>
  
  <p>Do I need to run that Console Application on a machine on that domain only or can be run on other domains too ?</p>
  
  <p>Can somebody provide me an example ?</p>
  
  <p><strong>UPDATE:</strong> Fetching the count of users code</p>
  
  <pre><code>DirectoryEntry myLdapConnection = createDirectoryEntry();
  DirectorySearcher search = new DirectorySearcher(myLdapConnection);
  search.Filter = "(&amp;objectClass=User)objectCategory=Person)userPrincipalName=*health2.com))";
  search.PropertiesToLoad.Add("sAMAccountName");
  SearchResultCollection allUsers = search.FindAll();
  for (int usersCount = 0; usersCount &lt; allUsers.Count; usersCount++)
  {
      SearchResult result = allUsers[usersCount];
      if (result.Properties["sAMAccountName"].Count &gt; 0)
      {
         string cn = result.Properties["sAMAccountName"][0].ToString();
         Console.WriteLine(cn);
         Console.ReadLine();
      }
  }
  Console.WriteLine(string.Format(@"Users Count - {0}", allUsers.Count.ToString()));
  Console.ReadLine();
  </code></pre>