I hate using NameTranslate, because it is a COM object, and because the output is often really hard to get into a clean, trimmed string. The netBIOS name isn’t a part of the AD domain object, but I suspected that the information could be gotten using a LDAP query. My searching lead me to a post on StackFlow. It wasn’t PowerShell, but it did give me an interesting hint. The filter’s objectcategory was “CrossRef”. I used this to port the code to PowerShell:
Function Get-DomainNetBIOSNameFromDNSName ($DomDNS){ $objRootDSE = [System.DirectoryServices.DirectoryEntry] "LDAP://rootDSE" $ConfigurationNC= $objRootDSE.configurationNamingContext $Searcher = New-Object System.DirectoryServices.DirectorySearcher $Searcher.SearchScope = "subtree" $Searcher.PropertiesToLoad.Add("nETBIOSName")| Out-Null $Searcher.SearchRoot = "LDAP://cn=Partitions,$ConfigurationNC" $searcher.Filter = "(&(objectcategory=Crossref)(dnsRoot=$domDNS)(netBIOSName=*))" ($Searcher.FindOne()).Properties.Item("nETBIOSName") }
This query is quick, and avoids the formatting problems with NameTranslate. There is a large table of LDAP queries on TechNet, but this one isn’t in the list.