title: Passing environment variables to a process in PowerShell 2.0 when the variable is changed multiple times
body: <p>I'm having some issue when it comes to passing the corresponding environment variables to a process. Below you can see part of my code so that you can understand what I'm trying to do.</p>
  
  <p>I have two EXE files that I need to run. The processes run some updates based on the location of the Environment variable <code>%MainFiles%</code>. When I run the code it seems the EXE files do not recognize the change. However, when i look under the Computer properties I do see that the variables are changed correctly.</p>
  
  <p>Does anyone know how could I force the process to recognize the change?
  Thanks</p>
  
  <pre class="lang-powershell prettyprint-override"><code>while ($i -lt $Size) {
    if ($TempEnv[$i] -eq "Done"){
      $ExitCode="Completed"
      return
    } else {
      $Temp = $TempEnv[$i]
      Write-Host ("Starting Update for  " + $Temp) -foregroundcolor "Green"
  
      [System.Environment]::SetEnvironmentVariable("MainFiles", "$Temp","Machine")
      [System.Environment]::GetEnvironmentVariable("MainFiles","Machine")
      Copy-Item $CopyInstallData -destination $Temp
      $process = Start-Process XMLUpgrade.exe -WorkingDirectory "C:\Program Files\Dtm" -wait
      $process = Start-Process Update.exe -WorkingDirectory "C:\Program Files\Dtm" -wait
  .
  .
  .
  </code></pre>