0
[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 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This will duplicate the data if it's already there.
Yes before running this command, in my script i test if my path are in the path environment variable. But, maybe i'm wrong, but the initial question are "How to add a value to existing system variable", and this command, create this behavior. If you have a better answer, don't hesitate to share it, i would be interested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.