title: How can I use nested quotes when calling a powershell script within a batch file?
body: <p>I have a DOS batch file that has a line that executes a powershell script. First I tried a very simple script with this line in the batch file:</p>
  
  <pre><code>powershell -command "get-date" &lt; nul
  </code></pre>
  
  <p>That worked great. But the script has nested double-quote characters, which can sometimes be escaped with a backtick (`) character. So then I tried this:</p>
  
  <pre><code>powershell -command "Write-Host `"hello world`"" &lt; nul
  </code></pre>
  
  <p>That also worked great. However, the script I need to run is pretty complicated and has more than one level of nested double-quote characters. I have taken the complicated script and simplified it to an example that has the same principles here:</p>
  
  <pre><code>[string]$Source =  "    `"hello world`" ";
  Write-Host $Source;
  </code></pre>
  
  <p>If I save this script inside a PS script file and run it, it works fine, printing out “hello world” including the double quotes, but I need to embed it in the line in the batch file. So I take the script and put it all on one line, and try to insert it into the batch file line, but it doesn’t work. I try to escape the double-quotes, but it still doesn’t work, like this:</p>
  
  <pre><code>powershell -command "[string]$Source =  `"    `"hello world`" `";Write-Host $Source;" &lt; nul
  </code></pre>
  
  <p>Is there a way to do what I want? You might ask why I am doing this, but it’s a long story, so I won’t go into the details.
  thanks</p>