使用Powershell在断开的网卡上设置静态IP,是否可能?

时间:2016-07-14 23:26:17

标签: powershell networking ip-address

我需要在未连接到网络的情况下在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还不熟悉,甚至可以配置断开连接的网卡的IP地址吗?

如果需要,我可以尝试其他技术。

2 个答案:

答案 0 :(得分:2)

...没关系

netsh interface ip set address "Ethernet" static 192.168.5.10 255.255.255.0

正是如此,可以从.ps1脚本运行。

答案 1 :(得分:0)

这是找到断开连接的适配器的方法

get-wmiobject win32_networkadapter -filter "netconnectionstatus = 7" | select netconnectionid, name, InterfaceIndex, netconnectionstatus
相关问题