Is there any way to supress the enclosing quotation marks around each command-line argument that powershell likes to generate and then pass to external executables for command line arguments that have spaces in them?
Here's the situation:
One way to unpack many installers is a command of the form:
msiexec /a <packagename> /qn TARGETDIR="<path to folder with spaces>"
Trying to execute this from powershell has proven quite difficult. Powershell likes to enclose parameters with spaces in double-quotes. The following lines:
msiexec /a somepackage.msi /qn 'TARGETDIR="c:\some path"'
msiexec /a somepackage.msi /qn $('TARGETDIR="c:\some path"')
$td = '"c:\some path"'
msiexec /a somepackage.msi /qn TARGETDIR=$td
All result in the following command line (as reported by the Win32 GetCommandLine() api):
"msiexec" /a somepackage.msi /qn "TARGETDIR="c:\some path""
This command line:
msiexec /a somepackage.msi TARGETDIR="c:\some path" /qn
results in
"msiexec" /a fooinstaller.msi "TARGETDIR=c:\some path" /qn
It seems that Powershell likes to enclose the results of expressions meant to represent one argument in quotation marks when passing them to external executables. This works fine for most executables. However, MsiExec is very specific about the quoting rules it wants and won't accept any of the command lines Powershell generates for paths have have spaces in them.
Is there any way to suppress this behavior?