用 PowerShell 下载文件,最常用的是 Invoke-WebRequest 命令,一行代码就能搞定。
powershell
**1、Invoke-WebRequest -Uri "https://example.com/file.zip" -OutFile "C:\Downloads\file.zip"**
-Uri 后面跟文件的下载地址
-OutFile 指定保存到本地的路径和文件名
日常用这个就够了。如果是大文件、网络不稳定的情况,更推荐 Start-BitsTransfer,它支持断点续传和自动重试,下载更稳:
powershell
**2、Start-BitsTransfer -Source "https://example.com/largefile.iso" -Destination "D:\Downloads\largefile.iso"**
🔧 其他常用方法
curl 命令:PowerShell 里可以直接用,适合习惯命令行操作的人:
powershell
**3、curl -o "C:\Downloads\file.zip" https://example.com/file.zip\*\*
```:ml-citation{ref="4" appearance="aggregated" data="citationList"}
.NET WebClient 类:兼容性最好,适合写脚本时用:
powershell
**4、(New-Object System.Net.WebClient).DownloadFile("https://example.com/file.zip", "C:\Downloads\file.zip")
```:ml-citation{ref="7,8" appearance="aggregated" data="citationList"}**
wget 命令:也是系统自带的别名,用法和上面类似:
powershell
**5、wget https://example.com/file.zip -OutFile "C:\Downloads\file.zip"
```:ml-citation{ref="4" appearance="aggregated" data="citationList"}**
⚠️ 几个小提醒
下载到 C:\ 或 D:\ 根目录时,可能需要管理员权限,否则会提示"访问被拒绝"。
如果目标地址是 HTTPS 且证书有问题,PowerShell 7+ 可以加 -SkipCertificateCheck 参数跳过证书验证(仅限测试环境)。
下载完成后建议用 Get-FileHash 校验文件哈希值,确认文件完整没被篡改。
以上方法都基于 Windows 自带的 PowerShell 环境,无需额外安装工具。