Refresh $env:path in Powershell? Refresh $env:path in Powershell? powershell powershell

Refresh $env:path in Powershell?


If you were running outside the context of a browser I would tell you to use

[System.Environment]::SetEnvironmentVariable(string name, string value, EnvironmentVariableTarget target) 

to change the Path variable for the user. That third parameter allows you to specify Process, User or Machine. If you specify either User or Machine the change is permanent and will appear in the env blocks of all programs that start after that. However, since you are running within the browser I don't think you would be able to do that.

If the user changes their path, that change will be available to future instances of the browser. Another option is to test (Get-Command) for the app you need in the path and if you can't find it, modify $env:Path yourself in the script each time it runs. That is, unless you don't know what the path should be.