我想根据用户提供的密码测试在目录中找到的.7zip。目前,t开关会导致7zip深入测试整个档案,我希望一旦密码返回true就会破坏它。
$CaseDirectory = Read-Host 'Please input Case directory'
$Password = Read-Host 'Please input Case password'
$7ZipPath = "C:\Program Files\7-Zip\7z.exe"
$Files = Get-ChildItem -Path $CaseDirectory -Recurse -Force -Filter *.7z
$Output = Foreach ($File in $Files)
{
& $7ZipPath "t" $File.FullName "-p$Password"
if (-not $?)
{
Write-Output $File "Wrong Password!"
} else {
Write-Output $File "Password Match"
}
Write-Output "================================================================"
Write-Host "Working.."
}
$Output | findstr /r /v "^$" | Out-File -FilePath
$CaseDirectory\PasswordTest_Output.txt
pause