PowerShell 中计算机的 NetBIOS 域 [英] NetBIOS domain of computer in PowerShell

查看:24
本文介绍了PowerShell 中计算机的 NetBIOS 域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 PowerShell 获取当前计算机的 NetBIOS(又名短")域名?

How can I get the NetBIOS (aka 'short') domain name of the current computer from PowerShell?

$ENV:USERDOMAIN 显示当前用户的域,但我想要当前机器所属的域.

$ENV:USERDOMAIN displays the domain of the current user, but I want the domain that the current machine is a member of.

我发现您可以在 VBScript 中很容易做到,但是显然 ADSystemInfo 在 PowerShell 中不太好用.

I've discovered you can do it pretty easily in VBScript, but apparently ADSystemInfo isn't very nice to use in PowerShell.

更新

这是我的最终解决方案,其中包含使用 Win32_NTDomain,但过滤到当前机器的域

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

推荐答案

在大多数情况下,默认的 NetBIOS 域名是 DNS 域名中最左边的标签,最多前 15 个字节(NetBIOS 名称有 15 个字节的限制)).NetBIOS 域名可以在安装 Active Directory 的过程中更改,但不能更改.

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.

WIN32_ComputerSystem WMI 对象提供有关 Windows 计算机的信息

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

所以域名为:

PS C:> (gwmi WIN32_ComputerSystem).Domain

但是在域安装中,会给出 DNS 名称.在这种情况下,您可以使用nbtstat -n 命令来查找NetBIOS 域名,该域名显示如下<1B>.

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

PowerShell 命令可能是:

The PowerShell Command may be :

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

这是使用 WMI 的另一种方式

Here is another way using WMI

PS C:> (gwmi Win32_NTDomain).DomainName

这篇关于PowerShell 中计算机的 NetBIOS 域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆