1

Am trying to install multiple softwares and some of them are dependent on others, means it looks up for some binary of softwares before install others. This installation process am doing it on Powershell and when the first software installation completed it will append the path location on Path environment variable. But its not showing the updated Path env variable for the current active session and due to that other softwares are getting failed to install.

Before install that software:

PS C:\Users\webapp> $env:Path C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramFiles\Pragma\Clients 

After install the software:

PS C:\Users\webapp> $env:Path C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramFiles\Pragma\Clients 

But it suppose to show:

PS C:\Users\webapp> $env:Path C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramFiles\Pragma\Clients;C:\apps-core\bin 

I was able to update the Path env variable for the active command prompt session using below metho

for /f "tokens=3*" %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path') do set syspath=%%A%%B set Path=%syspath% 

but am not sure how can I achieve the same with Powershell.

5
  • 2
    See stackoverflow.com/questions/714877/… Commented Dec 23, 2016 at 17:44
  • 1
    Env variables are drives in PS, they are not propagated back when u update the $env:XX variables. Try [Environment]::SetEnvironmentVariable("YourVariableName", "Test value.", "Machine") Use "User" instead of Machine, if u want to set a var only for a current user Commented Dec 23, 2016 at 17:52
  • 1
    $env:Path =[System.Environment]::GetEnvironmentVariable("Path","Machine") should update the values Commented Dec 24, 2016 at 5:32
  • @Abhijithpk Its working thanks! Commented Dec 26, 2016 at 6:52
  • @AtomicFireball Thanks! I found the below solution from the given link to update for both Active session and permanent [Environment]::SetEnvironmentVariable("Path", $env:Path + ";<mypath>", [EnvironmentVariableTarget]::Machine) Commented Dec 26, 2016 at 6:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.