Kippix
Kippix

Reputation: 33

powershell - inserting 7-zip parameters as variables

I am trying to run a script which archive specific directory and exclude some type of files. Problem is that if i try to insert some of parameters to main 7z command - those parameters doesn't work here is my code:

$source = "c:\source"
$destination = "d:\dest"
$date = get-date -UFormat "%d-%m-%Y"
$name = "D-"+$date+".zip"
$ExcludeFileTypes= "-x!'*.css' -x!'*.exe' -x!'*.dll' -x!'*.iso' -x!'*.ace' -x!'*.arj' -x!'*.jar' -x!'*.bz2' -x!'*.lha' -x!'*.lzh' -x!'*.rar' -x!'*.zip' -x!'*.tar' -x!'*.tgz'"
7z a "$destination$name" "$source" -r $ExcludeFileTypes -mx=9

If i replace $ExcludeFileTypes with its value - 7z command works. I have no idea where could be a problem. I guess that I can't work with variables like that.

Upvotes: 2

Views: 1059

Answers (1)

Gabe Perez
Gabe Perez

Reputation: 352

I had the same issue while ago trying to execute msi installers from command line. Try executing it like this:

$cmdargs = "a $destination$name $source -r $ExcludeFileTypes -mx=9"
Start-Process -FilePath c:\tools\7z.exe -ArgumentList $cmdargs

Upvotes: 3

Related Questions