I’m using invoke-expression in PowerShell to create an archive, but it’s not working due to spaces in the exe path. These are my variables:
Set-Variable -name DIRRELEASE -value (Join-Path $env:UserProfile "\Documents\Coding\_Projects\ChickenPing\trunk\Dist\current\")
$srcPath = (Join-Path $DIRRELEASE ("myapp_1.90-src.zip"))
Set-Variable -name WinRarFilter -value "-x*\.svn -x*\.svn\* -x*\nutrition.db3"
Set-Variable -name WinRarOpts -value "-r -s -m5 -inul"
$WinRar = `"C:\Program Files\Winrar\winrar.exe`"
#Then using this to invoke:
Invoke-Expression ($WinRAR + " a " + $srcPath + " " + $WinRARFilter + " * " + $WinRAROpts)
When I run the script I get this error:
The term ‘a’ 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 correct and try
again. At line:1 char:3
+ a <<<< C:\Users\Echilon\Documents\Coding_Projects\MyApp\trunk\Dist\c
urrent\myapp_1.95-src.zip -x*.svn -x*.svn* -x*\nutrition.db3 * -r
-s – m5 -inul
+ CategoryInfo : ObjectNotFound: (a:String) [], CommandNotFoundEx ception
+ FullyQualifiedErrorId : CommandNotFoundException
I just can’t find the right combination of quotes and plusses.
You could make this a lot easier to work with by using the call operator
&.