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

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

问题描述

我怎样才能获得的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

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

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