title: Call parameters in Powershell script in Jenkins
body: <p>I need to run a powershell script in a function called by Jenkins. When calling this function, two other parameters/variables are included. This is a sample of my code:</p>
  <pre><code>        powershell '''
              $Headers = @{&quot;ApiKey&quot;=&quot;$env:myKey&quot;}
              $jsonBody = @{
                  varOne= '$env:params.varOne'
                  varTwo = '$env:params.varTwo'} | ConvertTo-Json -Depth 10
  
              Invoke-RestMethod -Method Post -Uri &quot;myUrl&quot; -Headers $Headers -Body $jsonBody
          '''
      
  </code></pre>
  <p>This is throwing a 'Bad Response' error. Note that if I hard code the values that are in the variable, the script works.
  I also try to wrap the script with withEnv but I got the same issue:</p>
  <pre><code>    withEnv([&quot;varOne=${params.varOne}, varTwo=${params.varTwo}&quot;]) {
      powershell '''
          $Headers = @{&quot;ApiKey&quot;=&quot;$env:myKey&quot;}
          $jsonBody = @{
              varOne= '$env:params.varOne'
              varTwo = '$env:params.varTwo'} | ConvertTo-Json -Depth 10
  
          Invoke-RestMethod -Method Post -Uri &quot;myUrl&quot; -Headers $Headers -Body $jsonBody
      '''
  }
  </code></pre>
  <p>Finally, I know I could call these variables successfully if I was using double quote instead of single ones</p>
  <pre><code>powershell &quot;&quot;&quot;
  some ps1 script
  &quot;&quot;&quot;
  </code></pre>
  <p>However, when I do that it says:</p>
  <pre><code>groovy.lang.MissingPropertyException: No such property: Headers
  </code></pre>