title: Execute Windows Powershell command copy text to clipboard (incl. `r`n ')
body: <p>I am trying to execute a powershell command to copy text to the windows clipboard including carriage returns and ALL special characters. I can execute the command ok using:</p>
  
  <pre><code>powershell.exe -command Set-Clipboard 'TEXT'
  </code></pre>
  
  <p>This is not in the powershell console directly so syntax differs.</p>
  
  <p>I was using double quotes around text, substituting carriage returns in original text with `r`n and escaping all other special characters with `
  It worked up until I got to a single ' which I understand is used by powershell to mean a literal text string.</p>
  
  <p>So I changed approaches and wrapped un-escaped text in single quotes (except substituting 1 ' for 2 ''). Of course `r`n within the single quoted text are interpreted literally so doesn't work. I have tried stringing them together outside single quoted text like:</p>
  
  <pre><code>'some text here' "`r`n" 'more text here'
  </code></pre>
  
  <p>This works in the console but not in the command. Tried adding + either side but still does not work. </p>
  
  <p>User "TessellatingHeckler" suggested -EncodedCommand but unfortunately I am unable to produce any version of base 64 encoded strings (to include in the command) which match the same string encoded via the PS console. So that is not going to work.</p>
  
  <p>I have been attempting to simply substitute carriage returns in the original text with an obscure string, wrap the text in single quotes (literal) and then substitute it back to `r`n within PS. I have gotten the substitution to work in the console directly but cannot figure out how to actually send it as a command.</p>
  
  <pre><code>powershell.exe -command Set-Clipboard $Str = 'this is a test--INSERT_CRLF_HERE--1234'; $Car = '--INSERT_CRLF_HERE--'; $clr = "`r`n"; $Str = $Str -replace $Car, $clr
  </code></pre>
  
  <p>Can the above command be modified to work? Is it possible to achieve the intended outcome without writing to a temp file? It is preferable to be able to use single quoted text blocks as it is more robust and lightweight than trying to escape everything (even spaces) in the original text.</p>