Powershell 脚本用于测试文件中的 zip 密码

Powershell 脚本用于测试文件中的 zip 密码

我有 powershell 脚本:

$passwords = Get-Content list.txt
$7ZipPath = '"C:\Program Files\7-Zip\7z.exe"'
$zipFile = ".\dane_7up.zip"
foreach ($password in $passwords)
{
    Write-Host $password
    $command = '"$7ZipPath t $zipFile -p $password"'
    iex $command
    if (-Not $?)
    {
        [console]::beep(500,300)
        return
    }
}
pause

我想检查 list.txt 文件中的某个密码是否与 zip 文件匹配。但目前脚本只是打印了 7-Zip 调用的行,并没有运行它。我应该在脚本中做哪些更改才能使其正常工作?

另外:当密码中带有空格时,我可以使用“”来转义密码吗?

答案1

$passwords = Get-Content "C:\path\passwords.txt"
$7ZipPath = "C:\Program Files\7-Zip\7z.exe"
$zipFile = "C:\path\file.zip"
foreach ($password in $passwords)
{
    Write-Host $password
    & $7ZipPath "t" $zipFile "-p$password"
    if (-Not $?)
    {
        Write-Host $password "is not the password."
    } else {
        Write-Host $password "is the password."
    }
}
pause

相关内容