Use the back of ` to avoid the special double quote, so that:
powershell -noexit -command $str = \"hello '123'" world\"; write-host $str
becomes the following:
powershell -noexit -command $str = \"hello '123'`" world\"; write-host $str
EDIT:
Option 1. If you prefer to use the powershell -file here, you can change the above to powershell -file and run the powershell script file. Use here-strings as much as you want.
Option 2. If you prefer not to deal with your special quote character inside the application for invoking / processing / script, you can switch to using single quotes. In this case, you only need to avoid single quotes by doubling them, for example:
powershell -noexit -command $str = 'hello ''123''" world'; write-host $str
Please note that I did not do anything with your double quote character, and it works fine.
Thus, your line replacement code can be a little easier to read and maintain, especially if the editor does not display this character correctly (for example, the Powershell console - a regular double quote is displayed instead).
source share