Setting Windows PowerShell environment variables

前端 未结 18 2011
日久生厌
日久生厌 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:31

    Changing the actual environment variables can be done by using the env: namespace / drive information. For example, this code will update the path environment variable:

    $env:Path = "SomeRandomPath";             (replaces existing path) 
    $env:Path += ";SomeRandomPath"            (appends to existing path)
    

    There are ways to make environment settings permanent, but if you are only using them from PowerShell, it's probably a lot better to use your profile to initiate the settings. On startup, PowerShell will run any .ps1 files it finds in the WindowsPowerShell directory under My Documents folder. Typically you have a profile.ps1 file already there. The path on my computer is

    C:\Users\JaredPar\Documents\WindowsPowerShell\profile.ps1
    

提交回复
热议问题