title: Powershell: gpg command parameters with embedded double quotes
body: <p>I'm trying to call gpg2 from a Powershell script. I need to pass parameters with embedded quotes but I get some very odd behavior when I look at the results from echoargs or the executable directly.</p>
  
  <pre><code>$Passphrase = "PassphraseWith!$#" #don't worry, real passphrase not hardcoded!
  $Filename = "\\UNC\path\with\a space\mydoc.pdf.pgp"
  $EncyptedFile = $Filename  -replace "\\", "/"
  $DecryptedFile = $EncyptedFile -replace ".pgp" , ""
  
  $args = "--batch", "--yes", "--passphrase `"`"$PGPPassphrase`"`"", "-o `"`"$DecryptedFile`"`"", "-d `"`"$EncyptedFile`"`""
  &amp; echoargs $args
  &amp; gpg2 $args
  </code></pre>
  
  <p>gpg requires me to use double quotes for the passphrase because it has symbols and for the paths because of a space (confirmed this works when I run a sample single command directly from command prompt). Also, gpg wants UNC paths with forward slashes (confirmed this works too).</p>
  
  <p>As you can see I am trying to wrap the passphrase and file paths with paired escaped double quotes because echoargs seems to indicate the outer quotes are being stripped off. Here is what i get from echoargs:</p>
  
  <pre><code>Arg 0 is &lt;--batch&gt;
  Arg 1 is &lt;--yes&gt;
  Arg 2 is &lt;--passphrase "PassphraseWith!$#"&gt;
  Arg 3 is &lt;-o "//UNC/path/with/a space/mydoc.pdf"&gt;
  Arg 4 is &lt;-d "//UNC/path/with/a space/mydoc.pdf.pgp"&gt;
  
  Command line:
  "C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\PSCX\Apps\EchoArgs.exe" --batch --yes "--pass
  phrase ""PassphraseWith!$#""" "-o ""//UNC/path/with/a space/mydoc.pdf""" "-d ""//UNC/path/with/a space/mydo
  c.pdf.pgp"""
  </code></pre>
  
  <p>However, gpg2 gives the following result (whether run from ISE or PS directly):</p>
  
  <p><code>gpg2.exe : gpg: invalid option "--passphrase "PassphraseWith!$#""</code></p>
  
  <p>If I try <code>&amp; gpg2 "$args"</code> to convert the array to a string then I get the following similar result:</p>
  
  <p><code>gpg2.exe : gpg: invalid option "--batch --yes --passphrase "PassphraseWith!$#"</code></p>
  
  <p>Any ideas on this one?</p>