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

使用Proxmox API PowerShell模块传递Hashtable参数失败求助

解决cv4pve-api-powershell网络配置参数传递失败问题

问题原因

  1. MAC地址格式不兼容:Proxmox API强制要求MAC地址使用XX:XX:XX:XX:XX:XX的冒号分隔格式,你的代码中传入的是横杠分隔的格式(如bc-54-a1-60-2c-25),触发参数验证错误。
  2. NetN参数解析缺陷:模块对嵌套Hashtable类型的NetN参数解析存在问题,无法正确转换为Proxmox API接受的字符串格式。

修复代码

foreach($mac in $passed_MACs){
    # 转换MAC地址格式为Proxmox要求的冒号分隔
    $formattedMac = $mac.Replace('-', ':')
    
    # 直接构建符合API格式的网络配置字符串
    $networkConfig = @{
        1 = "model=e1000,bridge=vmbr0,macaddr=$formattedMac"
    }

    $storageConfig = @{ 1 = 'local-lvm:32' }
    $bootableIso = @{ 1 = 'local:iso/ubuntu.iso' }

    $nextId = Get-PveClusterNextid
    $createVM = New-PveNodesQemu -Node $node -Vmid $nextId.Response.data -Memory 2048 -ScsiN $storageConfig -IdeN $bootableIso -NetN $networkConfig
    
    $createVM | Out-File -FilePath .\test.txt -Append
    $createVM.Parameters | Out-File -FilePath .\test.txt -Append
}

备选方案(更可靠)

如果NetN参数依然报错,可以直接使用-Net1这类单个参数传递网络配置,绕开Hashtable解析逻辑:

foreach($mac in $passed_MACs){
    $formattedMac = $mac.Replace('-', ':')
    $storageConfig = @{ 1 = 'local-lvm:32' }
    $bootableIso = @{ 1 = 'local:iso/ubuntu.iso' }

    $nextId = Get-PveClusterNextid
    $createVM = New-PveNodesQemu -Node $node -Vmid $nextId.Response.data -Memory 2048 `
                                -Scsi1 'local-lvm:32' -Ide1 'local:iso/ubuntu.iso' `
                                -Net1 "model=e1000,bridge=vmbr0,macaddr=$formattedMac"
    
    $createVM | Out-File -FilePath .\test.txt -Append
    $createVM.Parameters | Out-File -FilePath .\test.txt -Append
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 06:17:36