用 PowerShell 查询天气

无需浏览器,通过 HTTP 获取一行天气摘要。

Windows网络APIPowerShell低风险
运行 (Invoke-RestMethod "https://wttr.in/Beijing?format=3"),得到一行天气预报。

01命令

命令
$ (Invoke-RestMethod "https://wttr.in/Beijing?format=3")

02作用说明

Invoke-RestMethod 执行 HTTP GET;当响应是纯文本时返回字符串。指向 wttr.in 的 format=3 即可得到紧凑的当前天气。它能自动把 JSON 解析成对象,是 PowerShell 的标准 Web 客户端。

03风险

风险低风险
使用条件Windows 10/11 with PowerShell 5.1 or PowerShell 7+
!注意: 请求依赖第三方服务和网络;企业代理环境可能需要配置 -Proxy。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Invoke-RestMethod
    Microsoft Learn · vendor-doc · 2026-09-20
    依据: Sends an HTTP request and returns the response as a string or object.

最后验证: 2026-09-20 · 分类: 网络

06相关方案