英文:
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
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论