Geeks With Blogs

Tangible Thoughts SharePoint, MOSS? and all the other questions

Its been quite a bit of struggle for me to find an accurate way of finding the netbios name of a domain from AD using System.DirectoryServices.

In case you are in the same jam here how you do it.

  1. Connect to AD using the following ldap url:


  2. When querying AD using the Directory Searcher object uses the following filter:


This should give you a record from AD containing the netbios name of the domain as the CN


AD stores the the netbios name in the Partitions naming container which is stored inside the configuration naming container.

A more detailed explanation and more samples can be found in the Active Directory Cookbook or its online version


Code sample:

// Method call

string netBiosName = GetNetBiosName( LDAP://CN=Partitions,CN=Configuration,DC=<DomainName>,DC=<local|com>,  "<userName"", "<password>");

// Method call


// Method Definition

private string GetNetBiosName(
    string ldapUrl,
    string userName,
    string password)
    string netbiosName = string.Empty;
    DirectoryEntry dirEntry = new DirectoryEntry(ldapUrl,
            userName, password);

    DirectorySearcher searcher = new DirectorySearcher(dirEntry);
    searcher.Filter = "netbiosname=*";

    SearchResultCollection results = searcher.FindAll();
    if (results.Count > 0)
        ResultPropertyValueCollection rpvc = results[0].Properties["CN"];
        netbiosName = rpvc[0].ToString();
    return netbiosName;

Crossposted from

Posted on Thursday, July 30, 2009 8:46 AM .NET | Back to top

Comments on this post: Find the NetBios Name of a domain in AD

# re: Find the NetBios Name of a domain in AD
Requesting Gravatar...
LDAP makes life so easy!
Left by used macbooks on Aug 04, 2009 4:29 PM

# re: Find the NetBios Name of a domain in AD
Requesting Gravatar...
OMG! Just what we've been looking for. No idea that silly name was stored in AD. Thank you!
Left by Shaka... on Apr 20, 2011 5:56 AM

# re: Find the NetBios Name of a domain in AD
Requesting Gravatar...

Thanks for this. But this code works only when the computer is joined in the domain. But this fails when querying the netbios name from the computer that is not in the domain but in the same network.
Left by saravanakumar on May 27, 2015 4:47 PM

Your comment:
 (will show your gravatar)

Copyright © Tariq | Powered by: | Join free