使用PowerShell和7zip - 密码保护文件夹中的每个文件

问题描述 投票:-3回答:1

我正在尝试密码保护文件夹中的10个文件(使用相同的密码)。完成后,我想拥有10个单独的zip文件,每个文件都有相同的密码。我的脚本如下所示,但它错误地说它无法打开文件作为存档。

$list=gci "C:\temp\test"
foreach ($file in $list)
{
   $file1=$file|select -ExpandProperty name
   & 'c:\program files\7-zip\7z.exe' a $file1.zip $file1 -p123
}

这是我得到的错误:

Open archive: testfile.pdf
7z.exe : ERROR: testfile.pdf
At line:6 char:5
+     & 'c:\program files\7-zip\7z.exe' a $file1.zip $file1 -p123
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (ERROR: testfile.pdf:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Can not open the file as archive
System ERROR:
Incorrect function.

任何帮助将不胜感激。谢谢

powershell 7zip
1个回答
-1
投票

哦,男孩......自己弄清楚..需要引号!!!

    & 'c:\program files\7-zip\7z.exe' a "$file1.zip" $file1 -p123
© www.soinside.com 2019 - 2024. All rights reserved.