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

Invoke-WebRequest cmdlet在PowerShell哪个版本中首次可用?

Invoke-WebRequest Cmdlet的可用版本及PS2.0下的替代方案

嘿,我来帮你理清这个问题~首先直接回答你的核心疑问:Invoke-WebRequest是从PowerShell 3.0版本开始正式引入的。

从你贴出的环境信息能看到,当前使用的是PowerShell 2.0:

$PSVersionTable
Name                           Value
----                           -----
CLRVersion                     2.0.50727.8762
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

这个版本里并没有Invoke-WebRequest这个cmdlet,所以你运行脚本的时候肯定会报错。

如果没办法升级PowerShell版本,想要实现同样的获取ipinfo.io返回IP的功能,可以用PowerShell 2.0支持的.NET类System.Net.WebClient来替代,修改后的脚本如下:

"start"
$webClient = New-Object System.Net.WebClient
$jsonContent = $webClient.DownloadString("http://ipinfo.io/json")
$ipObject = ConvertFrom-Json $jsonContent
$ipObject.ip
"done"

这个写法简洁直观,完全适配你的PS2.0环境,能实现和原脚本一样的效果。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:57:20