使用PowerShell解压VBR补丁包失败问题求助
解决Veeam补丁更新脚本的解压错误问题
问题详情
要为100多台服务器更新VBR补丁,编写的PowerShell脚本可正常下载补丁包,但解压环节出现异常——脚本显示已完成解压,但运行补丁程序时提示存储错误;单独执行Expand-Archive命令也报相同错误。
原脚本代码
#$VeeamVersion = Get-ItemProperty "HKLM:\Software\Veeam\Veeam Backup and Replication" | Select-Object -ExpandProperty DisplayVersion $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $VeeamVersion = (Get-Item 'C:\Program Files\Veeam\Backup and Replication\Backup\Packages\VeeamDeploymentDll.dll').VersionInfo |select -ExpandProperty FileVersion if ($VeeamVersion -eq "11.0.1.1261") { Write-Host "Veeam Backup and Replication version 11.0.1.1261 is installed on your PC" $DownloadUrl = "https://download2.veeam.com/VBR/v11/VeeamBackup&Replication_11.0.1.1261_20230227.zip" } elseif ($VeeamVersion -eq "12.0.0.1420") { Write-Host "Veeam Backup and Replication version 12.0.0.1420 is installed on your PC" $DownloadUrl = "https://download2.veeam.com/VBR/v12/VeeamBackup&Replication_12.0.0.1420_20230412.zip" } else { Write-Host "Neither Veeam Backup and Replication version 11.0.1.1261 nor version 12.0.0.1420 is installed on your PC" } if ($DownloadUrl) { New-Item -Path d:\ -name "veeam_update" -ItemType "Directory" $DownloadPath = "d:\Veaam_update" # 此处存在拼写错误:应为veeam_update if (Test-Path "$DownloadPath\veeam*.zip") { Write-Host "Veeam Backup and Replication is already downloaded" } else { Write-Host "Downloading Veeam Backup and Replication..." Invoke-WebRequest -Uri $DownloadUrl -OutFile "$DownloadPath\veeam.zip" Expand-Archive -LiteralPath "$DownloadPath\veeam.zip" -DestinationPath "$DownloadPath" Write-Host "Veeam Backup and Replication downloaded successfully" } Write-Host "Installing Veeam Backup and Replication silently..." #Start-Process "D:\Veaam_update\*.exe" -ArgumentList "/S" -Wait Write-Host "Veeam Backup and Replication installed successfully" }
错误信息
Exception calling "ExtractToFile" with "3" argument(s): "The archive entry was compressed using an unsupported compression method." At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:1059 char:25 + ... [System.IO.Compression.ZipFileExtensions]::ExtractToFile( ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : InvalidDataException
解决方案
1. 修正路径拼写错误
脚本中创建的目录是d:\veeam_update,但$DownloadPath变量写成了d:\Veaam_update(拼写错误,少了一个e),这会导致下载和解压路径不匹配,是潜在问题,需先修正。
2. 替换解压工具
Windows自带的Expand-Archive依赖.NET System.IO.Compression,不支持Veeam补丁包可能使用的LZMA2或Deflate64等压缩算法,建议用7-Zip命令行工具替代:
- 确保服务器已安装7-Zip,若未安装,可通过脚本静默安装(提前下载7-Zip安装包到共享路径)。
- 用7-Zip命令行解压:
& "C:\Program Files\7-Zip\7z.exe" x "$DownloadPath\veeam.zip" -o"$DownloadPath" -y
3. 可选:添加文件哈希校验
下载后校验文件哈希,避免因包损坏导致解压失败,可在Veeam官网获取对应补丁包的哈希值,添加校验逻辑。
修改后的脚本示例
$ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $VeeamVersion = (Get-Item 'C:\Program Files\Veeam\Backup and Replication\Backup\Packages\VeeamDeploymentDll.dll').VersionInfo | Select-Object -ExpandProperty FileVersion $DownloadUrl = $null if ($VeeamVersion -eq "11.0.1.1261") { Write-Host "已安装Veeam Backup and Replication 11.0.1.1261" $DownloadUrl = "https://download2.veeam.com/VBR/v11/VeeamBackup&Replication_11.0.1.1261_20230227.zip" # 可选:添加对应哈希值 # $ExpectedHash = "XXX" } elseif ($VeeamVersion -eq "12.0.0.1420") { Write-Host "已安装Veeam Backup and Replication 12.0.0.1420" $DownloadUrl = "https://download2.veeam.com/VBR/v12/VeeamBackup&Replication_12.0.0.1420_20230412.zip" # $ExpectedHash = "XXX" } else { Write-Host "未检测到目标版本的Veeam Backup and Replication" exit 1 } if ($DownloadUrl) { $DownloadPath = "d:\veeam_update" # 创建目录(已存在则不报错) New-Item -Path $DownloadPath -ItemType Directory -Force | Out-Null $ZipPath = Join-Path -Path $DownloadPath -ChildPath "veeam.zip" if (Test-Path (Join-Path -Path $DownloadPath -ChildPath "veeam*.zip")) { Write-Host "补丁包已下载" } else { Write-Host "正在下载补丁包..." Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipPath # 可选:哈希校验 # $ActualHash = (Get-FileHash -Path $ZipPath -Algorithm SHA256).Hash # if ($ActualHash -ne $ExpectedHash) { # Write-Host "补丁包损坏,下载失败" # Remove-Item -Path $ZipPath -Force # exit 1 # } Write-Host "正在解压补丁包..." # 使用7-Zip解压 if (Test-Path "C:\Program Files\7-Zip\7z.exe") { & "C:\Program Files\7-Zip\7z.exe" x $ZipPath -o"$DownloadPath" -y | Out-Null if ($LASTEXITCODE -eq 0) { Write-Host "解压成功" } else { Write-Host "解压失败" exit 1 } } else { Write-Host "未检测到7-Zip,请先安装" exit 1 } } Write-Host "正在静默安装补丁..." $SetupExe = Get-ChildItem -Path $DownloadPath -Filter "*.exe" | Select-Object -First 1 -ExpandProperty FullName if ($SetupExe) { Start-Process -FilePath $SetupExe -ArgumentList "/S" -Wait -NoNewWindow if ($LASTEXITCODE -eq 0) { Write-Host "补丁安装成功" } else { Write-Host "补丁安装失败,错误码:$LASTEXITCODE" } } else { Write-Host "未找到安装程序" } }
内容的提问来源于stack exchange,提问作者WebsGhost
相关产品推荐
相关产品推荐

