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.

Karthi1234
  • 949
  • 1
  • 8
  • 28
  • 2
    See http://stackoverflow.com/questions/714877/setting-windows-powershell-path-variable – AtomicFireball Dec 23 '16 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 – Prageeth Saravanan Dec 23 '16 at 17:52
  • 1
    $env:Path =[System.Environment]::GetEnvironmentVariable("Path","Machine") should update the values – ClumsyPuffin Dec 24 '16 at 05:32
  • @Abhijithpk Its working thanks! – Karthi1234 Dec 26 '16 at 06: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 + ";", [EnvironmentVariableTarget]::Machine)` – Karthi1234 Dec 26 '16 at 06:53

0 Answers0