07-21-2023, 06:42 PM
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][1], but apparently [ADSystemInfo isn't very nice to use][2] in PowerShell.
*Update*
Here's my final solution incorporating the suggestion of using [Win32_NTDomain][3], but filtering to the current machine's domain
$wmiDomain = Get-WmiObject Win32_NTDomain -Filter "DnsForestName = '$( (Get-WmiObject Win32_ComputerSystem).Domain)'"
$domain = $wmiDomain.DomainName
[1]:
$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][1], but apparently [ADSystemInfo isn't very nice to use][2] in PowerShell.
*Update*
Here's my final solution incorporating the suggestion of using [Win32_NTDomain][3], but filtering to the current machine's domain
$wmiDomain = Get-WmiObject Win32_NTDomain -Filter "DnsForestName = '$( (Get-WmiObject Win32_ComputerSystem).Domain)'"
$domain = $wmiDomain.DomainName
[1]:
[To see links please register here]
[2]:[To see links please register here]
[3]:[To see links please register here]