Win7下PowerShell 2.0下载微软MSE定义文件失败求助
解决Windows 7 PowerShell 2.0下载MSE定义文件fwlink链接失败问题
问题原因
你的脚本下载普通HTTPS文件正常,但fwlink链接报错,核心原因有两点:
- Windows 7默认仅启用TLS 1.0,而微软当前服务器已不再支持旧版TLS协议,导致连接中断;
- PowerShell 2.0的
WebClient默认未显式启用自动重定向,无法正确处理fwlink的跳转逻辑。
可行解决方案
方案一:强制启用TLS 1.2并开启自动重定向
修改脚本,先指定TLS版本,同时显式开启WebClient的自动重定向功能:
# 强制启用TLS 1.2(适配微软服务器的协议要求) [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $url = "https://go.microsoft.com/fwlink/?linkid=87341" $path = "C:\temp\update.exe" # 确保目标目录存在,不存在则创建 $targetDir = Split-Path -Parent $path if (-not (Test-Path -PathType Container $targetDir)) { New-Item -ItemType Directory -Path $targetDir -Force | Out-Null } # 创建WebClient实例并启用自动重定向 $webClient = New-Object Net.WebClient $webClient.AllowAutoRedirect = $true try { $webClient.DownloadFile($url, $path) Write-Host "下载完成,文件路径:$path" } catch { Write-Error "下载失败:$_" } finally { # 释放资源 $webClient.Dispose() }
方案二:手动解析fwlink真实下载链接
如果自动重定向仍有问题,可以先手动获取fwlink跳转后的真实URL,再直接下载:
# 启用TLS 1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $fwlinkUrl = "https://go.microsoft.com/fwlink/?linkid=87341" $path = "C:\temp\update.exe" # 发送请求获取重定向后的真实链接 $request = [Net.HttpWebRequest]::Create($fwlinkUrl) $request.AllowAutoRedirect = $false $response = $request.GetResponse() $realDownloadUrl = $response.GetResponseHeader("Location") $response.Dispose() # 下载真实链接对应的文件 $webClient = New-Object Net.WebClient try { $webClient.DownloadFile($realDownloadUrl, $path) Write-Host "下载完成,文件路径:$path" } catch { Write-Error "下载失败:$_" } finally { $webClient.Dispose() }
注意事项
- 确保Windows 7已安装支持TLS 1.2的系统补丁(如KB3140245),否则无法启用TLS 1.2协议;
- 两个方案均不依赖Windows Update或BITS服务,符合你的系统限制要求;
- 若仍报错,可先在PowerShell中执行
[Net.ServicePointManager]::SecurityProtocol,确认输出是否包含Tls12,若未包含则说明补丁未安装或协议未生效。
内容的提问来源于stack exchange,提问作者killingtime
相关产品推荐
相关产品推荐

