Setting Windows PowerShell environment variables

前端 未结 18 2036
日久生厌
日久生厌 2020-11-22 11:03

I have found out that setting the PATH environment variable affects only the old command prompt. PowerShell seems to have different environment settings. How do I change the

18条回答
  •  时光说笑
    2020-11-22 11:35

    Although the current accepted answer works in the sense that the path variable gets permanently updated from the context of PowerShell, it doesn't actually update the environment variable stored in the Windows registry.

    To achieve that, you can obviously use PowerShell as well:

    $oldPath=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path
    
    $newPath=$oldPath+’;C:\NewFolderToAddToTheList\’
    
    Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH –Value $newPath
    

    More information is in blog post Use PowerShell to Modify Your Environmental Path

    If you use PowerShell community extensions, the proper command to add a path to the environment variable path is:

    Add-PathVariable "C:\NewFolderToAddToTheList" -Target Machine
    

提交回复
热议问题