$wmiDomain = Get-WmiObject Win32_NTDomain -Filter "DnsForestName = '$( (Get-WmiObject Win32_ComputerSystem).Domain)'" $domain = $wmiDomain.DomainName PS C:> Get-WmiObject Win32_ComputerSystem Domain : WORKGROUP Manufacturer : Hewlett-Packard Model : HP EliteBook 8530w (XXXXXXXXX) Name : ABCHPP2 PrimaryOwnerName : ABC TotalPhysicalMemory : 4190388224 PS C:> (gwmi WIN32_ComputerSystem).Domain nbtstat -n | Select-String -Pattern "^ *(.*) *<1B>.*$" | % {$_ -replace '^ *(.*) *<1B>.*$','$1'} PS C:> (gwmi Win32_NTDomain).DomainName # Retrieve Distinguished Name of current domain. $Domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() $Root = $Domain.GetDirectoryEntry() $Base = ($Root.distinguishedName) # Use the NameTranslate object. $objTrans = New-Object -comObject "NameTranslate" $objNT = $objTrans.GetType() # Invoke the Init method to Initialize NameTranslate by locating # the Global Catalog. Note the constant 3 is ADS_NAME_INITTYPE_GC. $objNT.InvokeMember("Init", "InvokeMethod", $Null, $objTrans, (3, $Null)) # Use the Set method to specify the Distinguished Name of the current domain. # Note the constant 1 is ADS_NAME_TYPE_1779. $objNT.InvokeMember("Set", "InvokeMethod", $Null, $objTrans, (1, "$Base")) # Use the Get method to retrieve the NetBIOS name of the current domain. # Note the constant 3 is ADS_NAME_TYPE_NT4. # The value retrieved includes a trailing backslash. $strDomain = $objNT.InvokeMember("Get", "InvokeMethod", $Null, $objTrans, 3) import-module activedirectory (Get-ADDomain -Identity (Get-WmiObject Win32_ComputerSystem).Domain).NetBIOSName