为现有系统变量(powershell)添加值


[Enviroment]::SetEnviromentVariable("Path", "d:/test/bin;c:/test", "Machine"

如果该变量已经存在并且包含其他值;如何调整此脚本以不覆盖现有条目。在添加新的附加值时?

当我需要使用powershell添加软件到环境路径时,我使用:

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

但我不知道是否有效,我肯定有更好的方法。

最新更新