title: Escape variable in sqlcmd / Invoke-SqlCmd
body: <p>I am using powershell and using <a href="https://msdn.microsoft.com/en-CA/library/cc281720.aspx" rel="noreferrer"><code>Invoke-SqlCmd</code></a>.  I am able to pass variables to SQL:</p>
  
  <pre><code>$variables = @( "MyVariable='hello'" )
  
  Invoke-SqlCmd `
      -ServerInstance 'localhost' `
      -Database 'master' `
      -Username 'matthew' `
      -Password 'qwerty' `
      -Query 'SELECT $(MyVariable) AS foo' `
      -Variable $variables
  </code></pre>
  
  <p>This gives me back <code>hello</code> as expected.  However, if I have a variable with a value containing an equals (<code>=</code>): </p>
  
  <pre><code>$variables = @("MyVariable='aGVsbG8NCg=='") # base64 encoded 'hello'
  </code></pre>
  
  <p>It gives me the following error:</p>
  
  <blockquote>
    <p>The format used to define the new variable for <code>Invoke-Sqlcmd</code> cmdlet is invalid. Please use the 'var=value' format for defining a new variable.</p>
  </blockquote>
  
  <p>I could not find any documentation on either <code>sqlcmd</code> or <code>Invoke-SqlCmd</code> on how I should escape values properly.</p>
  
  <p>How do I escape variables sent to <code>sqlcmd</code> / <code>Invoke-SqlCmd</code>?</p>