使用带7zip密码的powershell保护文件夹中的每个文件

使用带7zip密码的powershell保护文件夹中的每个文件,powershell,7zip,Powershell,7zip,我试图用密码保护文件夹中的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 -p12

我试图用密码保护文件夹中的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.

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

哦,孩子……我自己想出来了……需要引号

    & 'c:\program files\7-zip\7z.exe' a "$file1.zip" $file1 -p123