根据 Andre Viot 的博客:
$adapters=(gwmi win32_networkadapterconfiguration )
Foreach ($adapter in $adapters){
Write-Host $adapter
$adapter.settcpipnetbios(0)
}
应禁用每个适配器上的 Netbios。不过,您可能希望更加敏锐,并确保在正确的接口上禁用 Netbios,因此我首先运行
Get-WmiObject Win32_NetworkAdapterConfiguration | Where IPAddress
,以查看当前连接的适配器列表。
ServiceName DHCPEnabled Index Description
----------- ----------- ----- -----------
VMSMP True 14 Intel Wireless Adapter
VMSMP True 29 Intel Ethernet Adapter
使用为“Where 对象”提供的过滤器选择要禁用的对象,如下所示。我想关闭 LAN 上的 NetBios。
$adapter = Get-WmiObject Win32_NetworkAdapterConfiguration | Where Description -like "*Ethernet*"
$adapter.SetTcpIPNetbios(0) | Select ReturnValue
ReturnValue
-----------
0
有很多可能的返回代码,就像很多一样。请务必“检查此处的列表”,并且不要懒惰地假设该功能适用于所有设备。您绝对应该首先测试一下并了解其后果。
http://www.alexandreviot.net/2014/10/09/powershell-disable-netbios-interface/我遍历每个适配器端口(我有 16 个),然后关闭所有端口上的 NetBIOS:
$i = 'HKLM:\SYSTEM\CurrentControlSet\Services\netbt\Parameters\interfaces'
Get-ChildItem $i | ForEach-Object {
Set-ItemProperty -Path "$i\$($_.pschildname)" -name NetBiosOptions -value 2
}
(Get-WmiObject Win32_NetworkAdapterConfiguration -Filter IpEnabled="true").SetTcpipNetbios(2)
,执行此操作的“现代方法”是通过 CIM cmdlet,示例来自 powershell.one:
# define the arguments you want to submit to the method
# remove values that you do not want to submit
# make sure you replace values with meaningful content before running the code
# see section "Parameters" below for a description of each argument.
$arguments = @{
TcpipNetbiosOptions = [UInt32](12345) # replace 12345 with a meaningful value
}
# select the instance(s) for which you want to invoke the method
# you can use "Get-CimInstance -Query (ADD FILTER CLAUSE HERE!)" to safely play with filter clauses
# if you want to apply the method to ALL instances, remove "Where...." clause altogether.
$query = 'Select * From Win32_NetworkAdapterConfiguration Where (ADD FILTER CLAUSE HERE!)'
Invoke-CimMethod -Query $query -Namespace Root/CIMV2 -MethodName SetTcpipNetbios -Arguments $arguments |
Add-Member -MemberType ScriptProperty -Name ReturnValueFriendly -Passthru -Value {
switch ([int]$this.ReturnValue)
{
0 {'Successful completion, no reboot required'}
1 {'Successful completion, reboot required'}
64 {'Method not supported on this platform'}
65 {'Unknown failure'}
66 {'Invalid subnet mask'}
67 {'An error occurred while processing an Instance that was returned'}
68 {'Invalid input parameter'}
69 {'More than 5 gateways specified'}
70 {'Invalid IP address'}
71 {'Invalid gateway IP address'}
72 {'An error occurred while accessing the Registry for the requested information'}
73 {'Invalid domain name'}
74 {'Invalid host name'}
75 {'No primary/secondary WINS server defined'}
76 {'Invalid file'}
77 {'Invalid system path'}
78 {'File copy failed'}
79 {'Invalid security parameter'}
80 {'Unable to configure TCP/IP service'}
81 {'Unable to configure DHCP service'}
82 {'Unable to renew DHCP lease'}
83 {'Unable to release DHCP lease'}
84 {'IP not enabled on adapter'}
85 {'IPX not enabled on adapter'}
86 {'Frame/network number bounds error'}
87 {'Invalid frame type'}
88 {'Invalid network number'}
89 {'Duplicate network number'}
90 {'Parameter out of bounds'}
91 {'Access denied'}
92 {'Out of memory'}
93 {'Already exists'}
94 {'Path, file or object not found'}
95 {'Unable to notify service'}
96 {'Unable to notify DNS service'}
97 {'Interface not configurable'}
98 {'Not all DHCP leases could be released/renewed'}
100 {'DHCP not enabled on adapter'}
default {'Unknown Error '}
}
}
注意:这需要以管理员身份运行。
TcpipNetbiosOptions
属性的每个网络适配器的 NetBIOS 状态:
Get-CimInstance -ClassName 'Win32_NetworkAdapterConfiguration' | Where-Object -Property 'TcpipNetbiosOptions' -ne $null | Select-Object -Property @('ServiceName', 'Description', 'TcpipNetbiosOptions');
对于每个网络适配器,值 1
表示启用 NetBIOS,值
2
表示禁用 NetBIOS。使用以下命令为每个具有非空 TcpipNetbiosOptions
属性的网络适配器禁用 NetBIOS:
Get-CimInstance -ClassName 'Win32_NetworkAdapterConfiguration' | Where-Object -Property 'TcpipNetbiosOptions' -ne $null | Invoke-CimMethod -MethodName 'SetTcpipNetbios' -Arguments @{ 'TcpipNetbiosOptions' = [UInt32](2) } -Confirm;
-Confirm
参数需要对每次更改进行确认,如果您有多个网络适配器并且只想更改其中某些网络适配器的 NetBIOS 状态,这会很有帮助。删除
-Confirm
参数即可简单地为之前显示的网络适配器的 all禁用 NetBIOS,从而使该过程更快。 应显示
ReturnValue
值列表。
ReturnValue
值为 0
表示操作成功。再次运行第一条命令以确认每个网络适配器的 NetBIOS 状态。微软官方文档: