Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解压受密码保护的存档的Powershell脚本_Powershell_7zip - Fatal编程技术网

解压受密码保护的存档的Powershell脚本

解压受密码保护的存档的Powershell脚本,powershell,7zip,Powershell,7zip,有许多不同的方法,承诺应该可以解压受密码保护的7zip文件,但我的同事认为这两种方法都不管用 所以我再次问有人能帮我吗 我有一个包含很多可能的密码值的文本文件。我读入单个值并迭代它们。然后我尝试执行一个命令,这会导致7zip将其解压。但我没有成功。事实上,我试了几个小时 你能帮帮我吗?这是目前为止的脚本代码 set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" $zipfilePath = "D:\NEU\CP 77 M2\CP

有许多不同的方法,承诺应该可以解压受密码保护的7zip文件,但我的同事认为这两种方法都不管用

所以我再次问有人能帮我吗

我有一个包含很多可能的密码值的文本文件。我读入单个值并迭代它们。然后我尝试执行一个命令,这会导致7zip将其解压。但我没有成功。事实上,我试了几个小时

你能帮帮我吗?这是目前为止的脚本代码

set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
$zipfilePath = "D:\NEU\CP 77 M2\CP.77_M2.part01.rar"
$content = Get-Content "C:\JDownloader v2.0\cfg\org.jdownloader.extensions.extraction.ExtractionExtension.passwordlist.json"
$destinationUnzipPath = Split-Path $zipfilePath
$passwords = ConvertFrom-Json $content

foreach ($password in $passwords)
{
    sz x  $zipfilePath $destinationUnzipPath -p"{password}";

    if (-Not $?)
    {
        [console]::beep(500,300)
        return
    }
}

假设密码列表被正确导入,问题是foreach循环中从未使用过不同的密码。让我们仔细看看:

# $passwords will now contain iterable set of passwords
$passwords = ConvertFrom-Json $content

# Try each password in the collection
# NB: it is bad practice to use variables with very similar names,
# though it is not the problem here    
foreach ($password in $passwords)
{
    # Call 7zip. Provide password as an argument.
    # Always use string literal {password} as decryption password.
    sz x  $zipfilePath $destinationUnzipPath -p"{password}";
所以问题是,即使使用了foreach,也从未尝试过单独的密码。至于修复,请将密码作为变量传递。这样,

# $passwords will now contain iterable set of passwords
$passwords = ConvertFrom-Json $content

# Try each password in the collection
foreach ($pass in $passwords)
{
    # Call 7zip. Provide password as an argument.
    sz x  $zipfilePath $destinationUnzipPath -p"$pass"
passwordlist.json的格式是什么?你的错误是什么?