title: how to escape space and ampersand in same time in powershell script that execute CMD
body: <p>In my Powershell script, I use "rmtshare.exe" to get information about share level permission. The "rmtshare.exe" can run perfectly under CMD environment with following command:</p>
  
  <pre><code>rmtshare.exe \\fs-sw-206\"C&amp;C FQT"
  </code></pre>
  
  <p>However, when I bring it to powershell environment. I can't figure out how to escape the space and the ampersand. Here is what I have tried so far which it is not working:</p>
  
  <pre><code>$rmtShare = "C:\rmtshare.exe"
  $ServerName = "fs-sw-206"
  $ShareName = "C&amp;C FQT"
  Invoke-Expression ($rmtShare + " " + "\\" + $ServerName + "\" + $ShareName)
  </code></pre>
  
  <p>The script above will give error message from the CMD, it said "if a sharename or path contains spaces, it should be enclosed in quotes". 
  If I changed the last line to this:</p>
  
  <pre><code>Invoke-Expression ($rmtShare + " " + "\\" + $ServerName + "\" + "'"+'"'+"'" + $ShareName +"'"+'"'+"'")
  </code></pre>
  
  <p>The error message was from Powershell itself, it said "The ampersand (&amp;) character is not allowed".  NOTE: if there is no ampersand, it works. So, now I am stuck because I need to escape both characters at the same time. </p>
  
  <p>Please offer your solution.</p>
  
  <p>You may need to download the rmtshare.exe to test out yourself. Download site: (<a href="https://www.symantec.com/connect/downloads/remove-folder-share-remote-computer" rel="nofollow noreferrer">https://www.symantec.com/connect/downloads/remove-folder-share-remote-computer</a>)</p>