title: Powershell Invoke-Command passing environment variables
body: <p>I wish to use Invoke-Command passing environment variables from the calling machine to the server where Invoke-Command is being executed.</p>
  
  <p>I want this to work:</p>
  
  <pre><code>Invoke-Command -ComputerName MyServer-ScriptBlock {
      $env:VAR=$using:env:USERNAME
      Write-Host $env:VAR
  }
  </code></pre>
  
  <p>But the output for this command is empty.  If I do not use the $using scope modifier, and just assign the variable directly I get the expected output ("VAR").</p>
  
  <pre><code>Invoke-Command -ComputerName MyServer -ScriptBlock {
     $env:VAR="VAR"
     Write-Host $env:VAR
  }
  </code></pre>
  
  <p>So, can I use $using with environment variables?  If not, is there an easy way to pass environment variables over to the remote computer where Invoke-Command is running?</p>