Powershell Add System Variable

前端 未结 3 819
北恋
北恋 2020-12-24 06:38

I am Trying To add a System Variable here using PowerShell:

I have tried both ways using

$env:MyTestVariable = \"My test variable.\"
         


        
3条回答
  •  死守一世寂寞
    2020-12-24 07:11

    Run PowerShell as an administrator (to get the necessary registry access permissions) then call out to the .Net framework to set it:

    [Environment]::SetEnvironmentVariable("MyTestVariable", "MyTestValue", "Machine")
    

    NB. it won't take effect within the same process, you'll have to make a new PowerShell process to see it.

提交回复
热议问题