下面的脚本能够生成7z文件并使用密码进行加密。但是,我无法使用密码打开文件。我的剧本怎么了?
工具
下面的脚本无法使用密码打开7z文件。
(我得到的错误>>。\ staff_2019-11-02.7z:加密文件中的校验和错误。\ staff_2019-11-02.7z。文件损坏或密码错误。)
powershell = e + p @ Bcr2生成的密码(例如密码)
[Reflection.Assembly]::LoadWithPartialName("System.Web") $randomPassword = [System.Web.Security.Membership]::GeneratePassword(8,2) if (-not (test-path "C:\7-Zip\7z.exe")) {throw "C:\7-Zip\7z.exe needed"} set-alias sz "C:\7-Zip\7z.exe" $timestamp = Get-Date -f yyyy-MM-dd $Source = ".\staff.txt" $Target = ".\staff_$timestamp.7z" $outputPassword = ".\staff_Password.txt" sz a -mx=0 -p$randomPassword -mhe=on -m0=lzma2 $Target $Source | Out-Null Write-Output "staff_$timestamp.7z password is $randomPassword" | Out-file $outputPassword -Append
能够使用密码 Abc123
打开7z文件if (-not (test-path "C:\7-Zip\7z.exe")) {throw "C:\7-Zip\7z.exe needed"}
set-alias sz "C:\7-Zip\7z.exe"
$timestamp = Get-Date -f yyyy-MM-dd
$Source = ".\staff.txt"
$Target = ".\staff_$timestamp.7z"
$outputPassword = ".\staff_Password.txt"
sz a -mx=0 -pAbc123-mhe=on -m0=lzma2 $Target $Source | Out-Null
答案 0 :(得分:1)
我怀疑它是PowerShell解析器,请尝试
sz a -mx=0 $('-p' + $randomPassword) -mhe=on -m0=lzma2 $Target $Source