【问题标题】:Using Powershell to set a static IP on a disconnected network card, is it possible?使用Powershell在断开的网卡上设置静态IP,可以吗?
【发布时间】:2016-07-14 23:26:17
【问题描述】:

我需要在未连接到网络时在 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/ 网卡在配置IP地址之前需要一个连接。

基本上,我正在尝试为数百台计算机中的附加 NICS 设置 IP 地址。在计算机投入生产之前,这个特定的 NIC 不会建立连接。我对 Powershell 还是很陌生,甚至可以配置断开连接的 NIC 的 IP 地址吗?

如果需要,我愿意尝试其他技术。

【问题讨论】:

    标签: powershell networking ip-address


    【解决方案1】:

    没关系...

    netsh interface ip set address "Ethernet" static 192.168.5.10 255.255.255.0
    

    正是这样做的,并且可以从 .ps1 脚本运行。

    【讨论】:

      【解决方案2】:

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

      get-wmiobject win32_networkadapter -filter "netconnectionstatus = 7" | select netconnectionid, name, InterfaceIndex, netconnectionstatus
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-09
        • 2020-06-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-28
        相关资源
        最近更新 更多