How can I get the NetBIOS (aka 'short') domain name of the current computer from PowerShell?
$ENV:USERDOMAIN displays the domain of the current user, but I want the domain that the current machine is a member of.
I've discovered you can do it pretty easily in VBScript, but apparently ADSystemInfo isn't very nice to use in PowerShell.
Update
Here's my final solution incorporating the suggestion of using Win32_NTDomain, but filtering to the current machine's domain
$wmiDomain = Get-WmiObject Win32_NTDomain -Filter "DnsForestName = '$( (Get-WmiObject Win32_ComputerSystem).Domain)'"
$domain = $wmiDomain.DomainName
Use
env:
to get environment settings through PowerShellNetBIOS:
$env:userdomain
FQDN:
$env:userdnsdomain
To see all the values:
Use the Active Directory Cmdlet Get-ADDomain:
This can also be done by using .NET framework (which is much faster than WMI)
Will return
In most cases, the default NetBIOS domain name is the leftmost label in the DNS domain name up to the first 15 bytes (NetBIOS names have a limit of 15 bytes). The NetBIOS domain name may be changed during the installation of the Active Directory, but it cannot be changed.
The WIN32_ComputerSystem WMI object gives informations on a Windows computer
So the domain Name is given by :
But in domain installation, the DNS name is given. In this case, you can use
nbtstat -n
command to find the NetBIOS domain name which is displayed like this<DOMAIN><1B>
.The PowerShell Command may be :
Here is another way using WMI
Using
NetGetJoinInformation
and P/Invoke:From Here