This is an ancient question and was initially answered by Greg Askew, but it's still appearing high up in Google search results and some may be confused by the .Net language in the answer. So I thought I'd add some simple examples.
For a forest with only one domain, you can query LDAP for the only Crossref object with a netBIOSname property located in the forest Partitions container.
In multi-domain forests, some extra logic will be needed to identify the specific domain you're interested in (maybe using the dnsRoot or nCName properties, as outlined by Greg Askew).
Remember that while LDAP queries are case-insensitive, object properties returned via LDAP are all lower case.
ldapsearch method
ldapsearch -h server.example.com -p 636 --useSSL [bind parameters] --baseDN "CN=Partitions,CN=Configuration,dc=example,dc=com" --scope one "(&(objectclass=Crossref)(netBIOSName=*))" netbiosname
Powershell using ADSI
This will work on any domain-joined computer without specifying a target DC - extra logic will be required to bind with an appropriate DC from an external environment.
$RootDSE = [System.DirectoryServices.DirectoryEntry]([ADSI]"LDAP://RootDSE") $Config = $RootDSE.Get("configurationNamingContext") $netbios = (New-Object DirectoryServices.DirectorySearcher(([adsi]"LDAP://CN=Partitions,$config"),'(&(objectclass=Crossref)(netBIOSName=*))')).FindOne().Properties['netbiosname']
Powershell using ActiveDirectory Powershell module
$partitions = (Get-ADForest).partitionscontainer $netbios = (Get-ADObject -LDAPFilter '(&(objectclass=Crossref)(netBIOSName=*))' -SearchBase $partitions -SearchScope onelevel -properties netbiosname).netbiosname
Note: COM methods on a domain-joined workstation may be faster, but the requirement here is for pure LDAP.