title: Powershell invoke-command and system variables
body: <p>I'm working on automating patches for a vendor app. I wanted to use powershell to iterate over a list of servers and use remoting to install on each box. However, one aspect is giving me a big headache. I have to call a cmd script provided by the vendor to set system variables prior to executing the installation script. So I call the script like so in powershell:</p>
  
  <pre><code>Invoke-Command -session $session {cmd /k ($args[0]+"\data\env.bat")} -Args $lesDestDir
  </code></pre>
  
  <p>I see it execute as it echoes its work in my powershell window, but subsequent calls to the installation script ie:</p>
  
  <pre><code>Invoke-Command -session $session {perl ".\rollout-2010.pl " $args[0] " NC"} -Args $rollout
  </code></pre>
  
  <p>immediately exit saying the various system variables it uses have not been set. Can someone explain to me the scope of the system variables? Do they cease to exist after the invoke-command completes? Do I need to string together the two script calls in a single invoke-command so that the second script can access the system variables or something like that?</p>