计算机在PowerShell中的NetBIOS域名域名、计算机、PowerShell、NetBIOS

2023-09-08 12:53:05 作者:下次请我

我怎样才能获得的NetBIOS(又名短),从PowerShell的当前计算机的域名?

$ ENV:USERDOMAIN显示当前用户的域名,但我想,目前该机的一员域

我发现,你可以做到这一点 pretty的容易在VBScript ,但显然< A HREF =htt​​p://technet.microsoft.com/en-us/library/ff730963.aspx> ADSystemInfo的是不是很好用在PowerShell中。

更新的

下面是我结合使用 Win32_NTDomain ,但过滤,目前该机的域

  $ wmiDomain = GET-WmiObject可以Win32_NTDomain筛选器DnsForestName ='$((GET-WmiObject可以Win32_ComputerSystem)。域)'
$域= $ wmiDomain.DomainName
 

解决方案 淘宝客怎么设置啊 配置域名是在电脑的那里啊 有没高手指教下

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

在WIN32_ComputerSystem WMI对象提供的信息在Windows计算机上

  PS C:\&GT;获取-WmiObject可以Win32_ComputerSystem

域:工作组
制造商:惠普
型号:惠普EliteBook8530瓦特(XXXXXXXXX)
名称:ABCHPP2
PrimaryOwnerName:ABC
TotalPhysicalMemory:4190388224
 

因此​​,域名为:

  PS C:\&GT; (gwmi WIN32_ComputerSystem)。域
 

但在域中的安装,DNS名称给出。在这种情况下,你可以使用的nbtstat -n 命令来查找其上显示这样的&LT NetBIOS域名; DOMAIN&GT;&LT; 1B&GT;

在PowerShell命令可能是:

 使用nbtstat -n |选择字符串-pattern(*)。^ *&LT; 1B&GT; * $| %{$ _ -replace^ *&LT(*); 1B&GT; * $','$ 1'}
 

下面是一个使用WMI另一种方式

  PS C:\&GT; (gwmi Win32_NTDomain).DomainName
 

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, but apparently ADSystemInfo isn't very nice to use in PowerShell.

Update

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

解决方案

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