NetBIOS domain of computer in PowerShell

后端 未结 9 1853
一个人的身影
一个人的身影 2021-01-04 01:20

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 th

9条回答
  •  春和景丽
    2021-01-04 01:40

    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

    PS C:\> Get-WmiObject Win32_ComputerSystem
    
    Domain              : WORKGROUP
    Manufacturer        : Hewlett-Packard
    Model               : HP EliteBook 8530w (XXXXXXXXX)
    Name                : ABCHPP2
    PrimaryOwnerName    : ABC
    TotalPhysicalMemory : 4190388224
    

    So the domain Name is given by :

    PS C:\> (gwmi WIN32_ComputerSystem).Domain
    

    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 <1B>.

    The PowerShell Command may be :

    nbtstat -n | Select-String -Pattern "^ *(.*) *<1B>.*$" | % {$_ -replace '^ *(.*) *<1B>.*$','$1'}
    

    Here is another way using WMI

    PS C:\> (gwmi Win32_NTDomain).DomainName
    

提交回复
热议问题