title: How to get user along with it's computer name from active directory
body: <p>I am new to using Active Directory and want to create search form which take username from user, do wildcard search using that and returns username found along with it's computer name. I am using following code:</p>
  
  <pre><code>private SearchResultCollection GetSearchResultCollection(string DomainName, string Filter)
  {
     try
     {
         /* Getting connection info. */
         Login ObjLogin = new Login();
         string ServerIP = ObjLogin.GetSystemSettingByName("LDAPServer");
         string Port = ObjLogin.GetSystemSettingByName("Port");
         string UserName = ObjLogin.GetSystemSettingByName("ADUsername");
         string Password = ObjLogin.GetSystemSettingByName("ADPassword");
  
         DirectoryEntry Ldap = new DirectoryEntry(@"LDAP://" + ServerIP + ":" + Port, UserName, Password);
  
         DirectorySearcher LdapSearcher = new DirectorySearcher(Ldap);
         LdapSearcher.Filter = Filter;
  
         return LdapSearcher.FindAll();
    }
    catch (Exception ex)
    {
        return null;
    }
  }
  
  
  public string FindUsernameInAD(string Username, out int Count)
  {
      Count = 0;
      string FoundUsername = Username;
  
      try
      {
         /* Getting domain name */
         Login ObjLogin = new Login();
         string DomainName = ObjLogin.GetSystemSettingByName("DomainName");
  
         SearchResultCollection LdapSearcherResults = GetSearchResultCollection(DomainName, "(&amp;(objectClass=user))");
  
         foreach (SearchResult resultLdap in LdapSearcherResults)
         {
            if ((resultLdap.Properties["sAMAccountName"] != null) &amp;&amp; (resultLdap.Properties["sAMAccountName"].Count &gt; 0))
            {
               if (resultLdap.Properties["sAMAccountName"][0].ToString().ToLower().Contains(Username.ToLower()))
               {
                  //return resultLdap.Properties["cn"][0].ToString() + "(" + resultLdap.Properties["sAMAccountName"][0].ToString() + "@" + Username + ")";
  
                  FoundUsername = resultLdap.Properties["sAMAccountName"][0].ToString();
                  Count++;
               }
            }
         }
      }
      catch (Exception ex)
      {
         /* Catch Exception Here */
         log.Error("Error in UserManager.cs, FindUsernameInAD function: " + ex.Message);
      }
  
      return FoundUsername;
  }
  </code></pre>
  
  <p>This code returns me username but no computer name so how do I get computer name? Also I want to know that "Is computer name for user is unique for each user in active directory?"</p>