我需要在Windows 10上设置未连接到网络的NIC的IP地址。 我试过:
Set-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress "192.168.5.10" -PrefixLength 24
和
New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress "192.168.5.10" -PrefixLength 24
Set-NetIPAddress不返回任何错误,但它不会设置地址。 它会切换 IPV4 属性中的选择以使用特定地址,但不填充值。
New-NetIPAddress给出以下错误:
New-NetIPAddress : Inconsistent parameters PolicyStore PersistentStore and Dhcp Enabled
At line:1 char:1
+ New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress "192.168.5.10" -Pr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [New-NetIPAddress], CimException
+ FullyQualifiedErrorId : Windows System Error 87,New-NetIPAddress
我做了一些挖掘,发现这里:http://www.darrylvanderpeijl.nl/tag/policystore/NIC 在配置 IP 地址之前需要连接。
基本上,我正在尝试为数百台计算机中的附加NICS设置IP地址。 在计算机处于生产状态之前,此特定 NIC 将没有连接。我对Powershell还很陌生,甚至可以配置断开连接的NIC的IP地址吗?
如果需要,我愿意尝试其他技术。
关系...
netsh interface ip set address "Ethernet" static 192.168.5.10 255.255.255.0
正是这样做的,可以从 .ps1 脚本运行。
这是查找断开连接的适配器的方式
get-wmiobject win32_networkadapter -filter "netconnectionstatus = 7" | select netconnectionid, name, InterfaceIndex, netconnectionstatus