中文翻译:如果条件与文本文件匹配,中断脚本。

huangapple go评论44阅读模式
英文:

Break script if the condition match with text file

问题

我正在尝试创建一个用于检查ZIP文件密码的脚本。密码存储在一个文本文件中。脚本正在正常工作,但我想在密码匹配时停止脚本,或者我能导出CSV文件吗?有人可以帮助我吗?
英文:

I am trying to create a script for checking the password for zip file. The passwords is stored in a text file. The script is working fine but I want to stop the script where the password is matched or can I export the csv file. can anyone help me with this

$passfile = Get-Content "C:\Users\parveen.kumar\Downloads\passwords.txt"
$7ZipexePath = "C:\Program Files-Zipz.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
    } 
}  

答案1

得分: 0

$passfile = Get-Content "C:\Users\parveen.kumar\Downloads\passwords.txt";
$7ZipexePath = "C:\Program Files-Zipz.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
    }
}
英文:
$passfile = Get-Content "C:\Users\parveen.kumar\Downloads\passwords.txt"
$7ZipexePath = "C:\Program Files-Zipz.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
    } 
}  

huangapple
  • 本文由 发表于 2023年2月6日 10:25:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75356841.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定