I have the following command that I need to run from a batch file:
PowerShell -Command "Start-Process cmd -ArgumentList '/C "MKLINK /D "C:Folder With SpacesAnother Folder" "%UserProfile%DocumentsFolder With Spaces""' -Verb RunAs"
however when this command is actually executed the quotes around the two folders with spaces in them is completely ignored and the command fails to run correctly. What would be the correct approach to escape the various quotes involved in this statement? I’ve tried using ` and ^ in front of the quotes surrounding the folder names but neither worked.
5
-
For
powershell.exe
, the Windows PowerShell CLI, to use"
characters passed to the-Command
parameter as part of the PowerShell code to execute, they must be escaped, in the simplest form as"
.- See this answer for details.
-
Due to
cmd.exe
‘s parsing quirks,"
characters embedded inside acmd /c "..."
call do not require additional escaping.
Therefore:
PowerShell -Command "Start-Process cmd -ArgumentList '/C "MKLINK /D "C:Folder With SpacesAnother Folder" "%UserProfile%DocumentsFolder With Spaces""' -Verb RunAs"