Adding a value to existing system variable (powershell)

157 Views Asked by At
[Enviroment]::SetEnviromentVariable("Path", "d:/test/bin;c:/test", "Machine"

If the variable already exists with other values in it; how can I adjust this script to not overwrite existing entries. While adding the new additional values?

1

There are 1 best solutions below

2
OlivierArgentieri On

When i need to add software to env path using powershell, i use this:

[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "Machine")+";<YOUR_PATH_HERE>", [System.EnvironmentVariableTarget]::Machine)

But i dont know if efficient, pretty sure a better way exist.