使用Powershell在断开连接的网卡上设置静态IP,是否可以?
Using Powershell to set a static IP on a disconnected network card, is it possible?
我需要在 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 return 没有任何错误,但它没有设置地址。它确实切换 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
我需要在 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 return 没有任何错误,但它没有设置地址。它确实切换 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