I am trying to password protect 10 files (using the same password) in a folder. Once completed, i would like to have 10 individual zip files each with the same password. My script is as follows but it errors out saying it cant open the file as archive.
$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
}
This is the error i get:
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.
Any help would be greatly appreciated. Thanks