While this is old, here are the two solutions I know that seem to reliably work to get the NETBIOS name for a domain without using the AD Powershell module:
Option 1 - ADSI query. Depends on network speed for LDAP lookup, but it's not that much slower than WMI:
$Config = $RootDSE.Get("configurationNamingContext")
$netbiosName = (new-object DirectoryServices.DirectorySearcher([adsi]"LDAP://CN=Partitions,$config",'(&(objectclass=Crossref)(netBIOSName=*))')).FindOne().Properties.nETBIOSName
Option 2 - another variation on the Win32_NTDomain
method given in other answers. This solves (hopefully) the problems with the empty workgroup shown on Server 2008 R2 systems and trusted domains.
In my example, the actual domain is MYTESTDOMAIN. The site name for the server is the same in both domains (deliberate design choice).
> Get-WmiObject -Class Win32_NTDomain
ClientSiteName :
DcSiteName :
Description : SRV101
DnsForestName :
DomainControllerAddress :
DomainControllerName :
DomainName :
Roles :
Status : Unknown
ClientSiteName : Servers
DcSiteName : Servers
Description : MYTESTDOMAIN
DnsForestName : test.my.com.au
DomainControllerAddress : \\10.0.100.100
DomainControllerName : \\MYTESTDC003
DomainName : MYTESTDOMAIN
Roles :
Status : OK
ClientSiteName : Servers
DcSiteName : Servers
Description : MYDOMAIN
DnsForestName : my.com.au
DomainControllerAddress : \\10.10.100.100
DomainControllerName : \\MYDC001
DomainName : MYDOMAIN
Roles :
Status : OK
Win32_ComputerSystem
gives the computer's domain DNS name - this is unique, at least in all my tests.
> gwmi Win32_ComputerSystem
Domain : test.my.com.au
Manufacturer : VMware, Inc.
Model : VMware Virtual Platform
Name : SRV101
PrimaryOwnerName : ICT
TotalPhysicalMemory : 12884430848
We can combine those into a nice WMI query that will only return the result for the domain that matches the Win32_ComputerSystem
Domain
> Get-WmiObject -Query "SELECT * FROM Win32_NTDomain WHERE DomainName LIKE '%' AND DNSForestName = `'$((gwmi win32_computersystem).domain)`'"
ClientSiteName : Servers
DcSiteName : Servers
Description : MYTESTDOMAIN
DnsForestName : test.my.com.au
DomainControllerAddress : \\10.0.100.100
DomainControllerName : \\MYTESTDC003
DomainName : MYTESTDOMAIN
Roles :
Status : OK
To wrap it up in a nice one-liner that returns only the NETBIOS name:
$netbiosName = (Get-WmiObject -Query "SELECT DomainName FROM Win32_NTDomain WHERE DomainName LIKE '%' AND DNSForestName = `'$((gwmi win32_computersystem).domain)`'").DomainName
Obviously it should be tested, but it's worked in all my tests - albeit domains with only a single trust.