I'm trying to use 7-Zip to backup some files inside a Powershell (v2) script.
I have:
$zipPath = "C:Program Files7-Zip7z.exe"
[Array]$zipArgs = "-mx=9 a", "`"c:BackupFolderackup.zip`"", "`"c:BackupFromackMeUp.txt`""
&$zipPath $zipArgs;
But when I run this I get:
7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Error:
Incorrect command line
Writing this to the screen I get:
C:Program Files7-Zip7z.exe -mx=9 a "c:BackupFolderackup.zip" "c:BackupFromackMeUp.txt"
So I assumed that I needed to put quotes around the path to 7z.exe, that gave me:
$zipPath = "C:Program Files7-Zip7z.exe"
$zipPath = " `"$zipPath`" "
[Array]$zipArgs = "-mx=9 a", "`"c:BackupFolderackup.zip`"", "`"c:BackupFromackMeUp.txt`""
&$zipPath $zipArgs;
But then I get the following error:
The term '"C:Program Files7-Zip7z.exe"' is not recognized as the name of a cmdlet, function, script file
, or operable program. Check the spelling of the name, or if a path was included, verify that the path is c
orrect and try again.
At C:BackupScriptBackup.ps1:45 char:22
+ & <<<< `"$zipPath`" $zipArgs;
+ CategoryInfo : ObjectNotFound: ("C:Program Files7-Zip7z.exe":String) [], CommandNotFound
Exception
+ FullyQualifiedErrorId : CommandNotFoundException
Writing it out gives me:
"C:Program Files7-Zip7z.exe" -mx=9 a "c:BackupFolderackup.zip" "c:BackupFromackMeUp.txt"
Which works as expected when pasting straight into a command window.
I have been trying to figure this out for a while, but assume I am missing something (probably quite obvious). Can anybody see what I need to do to make this run?
question from:
https://stackoverflow.com/questions/25287994/running-7-zip-from-within-a-powershell-script 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…