PowerShell修改环境变量

如果你搜索本问题,多半会来到StackOverflow中看到这个回答

setx /M PATH "%PATH%;<your-new-path>"

Note: CMD中执行

正如该回答的某个回复提到的:

DO NOT USE THIS. setx will truncate PATH to 1024 characters. If PATH was changed before by being prepended with more directories, you will lose most of the original PATH contents!

这个会有1024个字符限制,如果你原有的%PATH%很长会被自动截断。

所以还是老实地调用.NET Framework的方法吧

$newPath = 'F:\common tools\git\bin;F:\common tools\python\app;F:\common tools\python\app\scripts;F:\common tools\ruby\bin;F:\masm32\bin;F:\Borland\BCC55\Bin'
$oldPath = [Environment]::GetEnvironmentVariable('PATH', 'Machine');
[Environment]::SetEnvironmentVariable('PATH', "$newPath;$oldPath",'Machine');

Note: PowerShell中执行

posted @   talentzemin  阅读(126)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示