You need to enable JavaScript to run this app. 通过Jenkins获取IP转可用整数时PowerShell报格式错误咨询
优惠活动
大模型
产品
解决方案
定价
更多

通过Jenkins获取IP转可用整数时PowerShell报格式错误咨询

需求与执行异常
  • 核心需求:从Jenkins的用户输入选项中获取用户填写的IP地址,将IP转换为可用的整数格式,最终写入FortiGate设备的配置文件中
  • 已尝试的PowerShell实现代码:
$source_subnet = "240.14.4.5"
$Subnet = $source_subnet
$Subnetint = [Int64]$Subnet
Write-Host $Subnetint
  • 执行异常:当用户输入的IP值为240.14.4.5时,PowerShell抛出类型转换错误,完整报错内容为:
Cannot convert value "240.14.4.5" to type "System.Int64". Error: "Input string was not in a correct format."

对应中文释义:无法将值“240.14.4.5”转换为System.Int64类型,错误原因为输入字符串格式不符合要求。

本质问题:IPv4点分十进制格式的IP字符串由四段数字加间隔点组成,不属于PowerShell可直接强制转换为Int64的纯数字格式,直接强转必然执行失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.11.11 14:45:08