PowerShell will strip outer quotes, as you can see here.
This is the same as why find.exe
doesn't work as expected in PowerShell.
You need to embed the double quotes inside single quotes, or escape the double quote by using `backticks`
or by doubling the double quote:
cmd /c '"C:\Program Files\myfile.exe"' -i '"C:\myconfig.sql"'
cmd /c "`"C:\Program Files\myfile.exe`"" -i "`"C:\myconfig.sql`""
cmd /c "`"C:\Program Files\myfile.exe`"" -i `"C:\myconfig.sql`"
cmd /c """C:\Program Files\myfile.exe""" -i C:\myconfig.sql
- ...
You can also use PowerShell 3.0's verbatim arguments symbol:
cmd /c --% "C:\Program Files\myfile.exe" -i "C:\myconfig.sql"
More about quoting rules in PowerShell is here.
However unless you need an internal command of cmd like dir
, for
... you should avoid calling via cmd. Just call the program directly from PowerShell:
try
{
"C:\Program Files\myfile.exe" -i "C:\myconfig.sql"
}