You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装Windows Server 2022 Azure版时,同款PowerShell命令执行报错

问题原因及解决办法

错误的核心原因是:你执行的(Get-NetAdapter).InterfaceIndex返回了数组类型的结果,但New-NetIPAddress的InterfaceIndex参数只接受单个无符号整数(UInt32)。

教程里的测试环境应该只有1个网络适配器,所以该表达式会返回单个索引值,命令能正常执行;而你的Windows Server 2022 Azure版实例上存在多个网卡,导致返回了一组索引值,参数类型不匹配才触发了这个转换错误。

解决步骤:

  1. 先执行以下命令查看所有网卡的详细信息,找到你需要配置IP的目标网卡:
    Get-NetAdapter
    
  2. 选择以下任意一种方式修正命令:
    • 直接指定已知的接口索引(比如查到目标网卡索引是2):
      New-NetIPAddress -IPAddress 10.0.2.4 -DefaultGateway 10.0.2.1 -PrefixLength 24 -InterfaceIndex 2
      
    • 通过网卡名称精准筛选(比如目标网卡名为"Ethernet"):
      New-NetIPAddress -IPAddress 10.0.2.4 -DefaultGateway 10.0.2.1 -PrefixLength 24 -InterfaceAlias "Ethernet"
      
    • 或者通过管道获取单个网卡的索引:
      New-NetIPAddress -IPAddress 10.0.2.4 -DefaultGateway 10.0.2.1 -PrefixLength 24 -InterfaceIndex (Get-NetAdapter -Name "Ethernet").InterfaceIndex
      

内容的提问来源于stack exchange,提问作者Nick Brown

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 07:22:36