Powershell 命令行禁用netbios?
我有一个以太网适配器和一个无线适配器,我一辈子都搞不清楚用于通过TCP/IP为系统上的所有适配器禁用Netbios的命令行(或powershell)。如果您对此有任何意见,我将不胜感激Powershell 命令行禁用netbios?,powershell,command-line-interface,netbios,Powershell,Command Line Interface,Netbios,我有一个以太网适配器和一个无线适配器,我一辈子都搞不清楚用于通过TCP/IP为系统上的所有适配器禁用Netbios的命令行(或powershell)。如果您对此有任何意见,我将不胜感激 根据安德烈·维奥特的博客: $adapters=(gwmi win32_networkadapterconfiguration ) Foreach ($adapter in $adapters){ Write-Host $adapter $adapter.settcpipnetbios(0) } 应在每
根据安德烈·维奥特的博客:
$adapters=(gwmi win32_networkadapterconfiguration )
Foreach ($adapter in $adapters){
Write-Host $adapter
$adapter.settcpipnetbios(0)
}
应在每个适配器上禁用Netbios。不过,您可能希望更清楚,并确保在正确的界面上禁用Netbios,因此我首先运行获取WmiObject Win32\u NetworkAdapterConfiguration |其中IPAddress
,查看当前连接的适配器列表
ServiceName DHCPEnabled Index Description
----------- ----------- ----- -----------
VMSMP True 14 Intel Wireless Adapter
VMSMP True 29 Intel Ethernet Adapter
使用提供给Where对象的过滤器选择要禁用的对象,如下所示。我想关闭局域网上的NetBios
$adapter = Get-WmiObject Win32_NetworkAdapterConfiguration | Where Description -like "*Ethernet*"
$adapter.SetTcpIPNetbios(0) | Select ReturnValue
ReturnValue
-----------
0
尽管有很多可能的返回码,就像很多一样。请确保并且不要懒洋洋地假设该功能将在每个设备上工作。你肯定应该先测试一下,并了解其后果
如果您试图在没有连接的适配器上设置NetBIOS的配置,您可以在注册表中更改设置,而不是直接使用SetTcpIPNetbios 我遍历每个适配器端口(我有16个),然后在所有端口上关闭NetBIOS:
$i = 'HKLM:\SYSTEM\CurrentControlSet\Services\netbt\Parameters\interfaces'
Get-ChildItem $i | ForEach-Object {
Set-ItemProperty -Path "$i\$($_.pschildname)" -name NetBiosOptions -value 2
}
从关于的其他回答和评论中,我使用此命令作为一行命令来禁用NetBIOS:
(获取WmiObject Win32_NetworkAdapterConfiguration-Filter IpEnabled=“true”)。SetTcpipNetbios(2)
作为一种“现代方式”,实现这一点的方法是通过CIM cmdlet,示例如下:
注意:这需要以管理员身份运行。使用以下命令获取每个具有非null属性的网络适配器的NetBIOS状态:
获取CimInstance-ClassName'Win32_NetworkAdapterConfiguration'|其中对象-属性'TCPIPNebiosOptions'-ne$null |选择对象-属性@('ServiceName','Description','TCPIPNebiosOptions')代码>
对于每个网络适配器,值1
表示已启用NetBIOS,值2
表示已禁用NetBIOS
使用以下命令为每个具有非空tcpipnebiostoptions
属性的网络适配器禁用NetBIOS:
获取CimInstance-ClassName'Win32_NetworkAdapterConfiguration'|其中对象-属性'TCPIPNebiosOptions'-ne$null |调用CimMethod-MethodName'SetTCPIPNebios'-Arguments@{'TCPIPNebiosOptions'=[UInt32](2)}-确认代码>
-Confirm
参数要求对每次更改进行确认,如果您有多个网络适配器,并且只想更改其中一些适配器的NetBIOS状态,则此参数非常有用。删除-Confirm
参数,只需对前面显示的所有网络适配器禁用NetBIOS即可,从而加快进程
应显示ReturnValue
值的列表。0
的ReturnValue
值表示操作成功。再次运行第一个命令以确认每个网络适配器的NetBIOS状态
Microsoft官方文档:
您可能会在上得到更好的答复。这是针对的问题,而不是针对ServerFault(或StackOverflow)。仔细想想,这实际上是谷歌的一个问题。settcpipnebios(0)
==通过DHCP启用NetBIOSSetTcpNetbios(2)
禁用它。另外,首先筛选支持IP的适配器列表也是有意义的。谢谢。我以前在谷歌上搜索过,但什么都没用。我没有意识到它有这么多的元素。不幸的是,.settcpipnebios(2)在网络适配器当前没有活动网络连接时不起作用(它返回84,“适配器上未启用IP”),因此在连接到网络之前不可能以这种方式禁用NetBIOS。有人知道在建立网络连接之前还可以使用的另一种方法吗?这真的很有帮助。这可以通过命令ipconfig/all
确认。
# 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 '}
}
}