Reputation: 46579
I'm running this ps command:
PS C:\Windows\system32> [Environment]::SetEnvironmentVariable( "Path"
, $env:Path + "; D:\Program Files (x86)\Java\bin"
, System.EnvironmentVariableTarget]::Machine )
I've started powershell as an admin. To me, that command should add the "; D:\Program..." string to the Path variable of the current machine. Yet, it doesn't and there's no failure. What am I doing wrong?
Upvotes: 1
Views: 592
Reputation: 25810
This works for me and does not need to restart console
PS C:\Users> $env:Path = "$($env:Path);c:\Scripts"
PS C:\Users> $env:Path
%SystemRoot%\system32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System
32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft Application Virtualization Client;C:\Program Files (x86)\Co
mmon Files\Roxio Shared\DLLShared\;c:\Scripts
This works only for the current session though. If you need to persist the updated path variable, you need to use the method in your question and restart the shell.
Upvotes: 3
Reputation: 46579
Ah, found the answer shortly after: you have to restart powershell to see any modified environment variables.
Upvotes: 0