powershell 如果条件与文本文件匹配,则中断脚本

zphenhs4  于 2023-02-23  发布在  Shell
关注(0)|答案(1)|浏览(105)

我正在尝试创建一个脚本来检查zip文件的密码。密码存储在文本文件中。脚本运行正常,但我想在密码匹配的地方停止脚本,或者我可以导出csv文件吗?有人能帮我吗

$passfile = Get-Content "C:\Users\parveen.kumar\Downloads\passwords.txt"
$7ZipexePath = "C:\Program Files\7-Zip\7z.exe"
$zipFile = "C:\users\parveen.kumar\Downloads\just.zip"
foreach ($password in $passwords)
{
    Write-Host $password
    & $7ZipexePath "t" $zipFile "-p$passfile"
    if (-Not $?)
    {
        Write-Host $password "This is incorrect password."
    } else {
        Write-Host $password "This is the correct password." -ForegroundColor Red
    } 
}
zf9nrax1

zf9nrax11#

$passfile = Get-Content "C:\Users\parveen.kumar\Downloads\passwords.txt"
$7ZipexePath = "C:\Program Files\7-Zip\7z.exe"
$zipFile = "C:\users\parveen.kumar\Downloads\just.zip"
foreach ($password in $passwords)
{
    Write-Host $password
    & $7ZipexePath "t" $zipFile "-p$passfile"
    if (-Not $?)
    {
        Write-Host $password "This is incorrect password."
    } else {
        Write-Host $password "This is the correct password." -ForegroundColor Red;Break
    } 
}

相关问题