Powershell: Reload the path in PowerShell Powershell: Reload the path in PowerShell powershell powershell

Powershell: Reload the path in PowerShell


Just to bring Rob's comment to light:

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 


Try getting the machine path and assigning it to the session's path.

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")


Easiest way, use Chocolatey (freeware). It works for both CMD and PowerShell. Then you will be able to reload PATH (with variable expansion) with a simple command:

refreshenv

Installation from cmd (requires administrator rights):

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Example usage:

> SET JAVA_HOME=c:/java/jdk6> SET PATH=%JAVA_HOME%/bin> ECHO %PATH%c:/java/jdk6/bin> SET JAVA_HOME=c:/java/jdk8> refreshenvRefreshing environment variables from registry for cmd.exe. Please wait...Finished..> echo %PATH%c:/java/jdk8/bin