NetBIOS domain of computer in PowerShell

后端 未结 9 1765
一个人的身影
一个人的身影 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

    OP is after "computer domain" so the answer would be $GetComputerDomain (below) but I will add the $GetUserDomain also for reference.

    $GetComputerDomain = ([System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()).Name
    $GetUserDomain = ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).Name
    

    I find the wmi (gwmi) option to be extremely slow, especially, when you are querying the Win32_NTDomain class. I have a multi-trusted domain environment and it takes forever when I just need that simple info quick.

    0 讨论(0)
  • 2021-01-04 01:44

    The below powershell command works great! I tested after trying various solutions.

    If you use the following .Net command:

     [System.Net.Dns]::GetHostByAddress('192.168.1.101').hostname
    

    It works too, but it is using DNS to resolve, in my case, we have WINS setup to support an application that requires it, so can't use it. Below is what I ended up using as part of a script I use to check for WINS registration for each client:

    $IPAddress = "<enterIPAddress>" (remove brackets, just enter IP address)
    
    (nbtstat -A $IPAddress | ?{$_ -match '\<00\>  UNIQUE'}).Split()[4]
    

    http://social.technet.microsoft.com/Forums/en-US/f52eb2c7-d55d-4d31-ab4e-09d65d366771/how-to-process-cmd-nbtstat-a-ipaddress-output-and-display-the-computer-name-in-powershell?forum=ITCG

    The above link has the thread and conversation.

    0 讨论(0)
  • 2021-01-04 01:45

    Use the Active Directory Cmdlet Get-ADDomain:

    (Get-ADDomain -Current LocalComputer).NetBIOSName
    
    0 讨论(0)
提交回复
热议问题