Hello there,
I just want to set extension exclusion from file (7zip utilization). If I write this command, it’s work perfectly :
7zip a -t7z -m0=lzma2 -mx=9 -mmt=on -mhe=on -p"$Password" $Target $itemsToSave ‘-xr!.lck’ '-xr!.log’
But, if I want to take exclusions from file in PowerShell, It doesn’t work :
$exclusion = get-content -Path "conf\exclusion.txt"
7zip a -t7z -m0=lzma2 -mx=9 -mmt=on -mhe=on -p"$Password" $Target $itemsToSave $exclusion
Here the result of file (exactly the same output with write-host $exclusion) :
‘-xr!.lck’ '-xr!.log’
Someone can help me ?
Thanks,
Clement.
Do the exclusion.txt file items contain the surrounding quotes? If so, they probably don’t need to be there.
Hello,
I tried with one, double quotes and without, but doesn’t work 
We are left to assume what you have in $target and $itemstosave - the question I am stuck at is why are you including items in $itemstosave that you want to exclude. Just exclude them when making your list. If this isn’t the case, please provide details about what you’re actually running. If I run your test with a path as the $itemstosave, the exclusions were ignored in the format specified.
Hello,
because in $itemtosave, i just set 4-5 generals folders. One folder can have 1000 or more files…
In $exclusion, I just want to exclude 2-3 extensions like *.lck, *.log or others…
"If I run your test with a path as the $itemstosave, the exclusions were ignored in the format specified"
--> Really ? :o I am running 7Zip 19.00, PWSH 5.1 (and 7.0.3).
Here a solution for someone who’s want do the same :
7zip a -t7z -m0=lzma2 -mx=9 -mmt=on -mhe=on -p"$resultPasswordArchive" $Target $itemsToSave1 -xr@“exclusion.txt”
In fileexclusion.txt, insert exclusions you want like :
*.log
*.lck
Problem solved.
Clement.