开发者

what would cause [Environment]::SetEnvironmentVariable to fail silently?

I'm running this ps command:

PS C:\Windows\system32> [Environment]::SetEnvironmentVariable( "Path"
, $env:Path + "; D:\Program 开发者_StackOverflowFiles (x86)\Java\bin"
, System.EnvironmentVariableTarget]::Machine )

I've started powershell as an admin. To me, that command should add the "; D:\Program..." string to the Path variable of the current machine. Yet, it doesn't and there's no failure. What am I doing wrong?


This works for me and does not need to restart console

PS C:\Users> $env:Path = "$($env:Path);c:\Scripts"
PS C:\Users> $env:Path
%SystemRoot%\system32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System
32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft Application Virtualization Client;C:\Program Files (x86)\Co
mmon Files\Roxio Shared\DLLShared\;c:\Scripts

This works only for the current session though. If you need to persist the updated path variable, you need to use the method in your question and restart the shell.


Ah, found the answer shortly after: you have to restart powershell to see any modified environment variables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜