Search code examples
powershellpowershell-2.0

How do find out short name of domain I'm in?


I want to return the short name of the domain the computer I am running on. I do not want the $env:USERDOMAIN because that is the domain the user is logged on to, which could be different to the domain the machine is in. If I do

(gwmi win32_computersystem).Domain

This gets me the FQDN, but I want something similar to return the short name (NETBIOS name?). I am currently parsing the FQDN, but I know this will lead to bugs later.

I don't have the Active Directory module installed, and company policy prevents me from installing it, so I can't simply use (Get-ADDomain).NetBIOSName from that module.


Solution

  • OK, last try.

    (net config workstation) -match 'Workstation domain\s+\S+$' -replace '.+?(\S+)$','$1'