Powershell Add System Variable

前端 未结 3 817
北恋
北恋 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:10

    Run PowerShell as an admin. Don't use this if you are trying to modify something like environmental extensions or environmental paths. No need to run refreshEnv and no need to open a new PowerShell window to see it

    $variableNameToAdd = "mytestVariableName"
    $variableValueToAdd = "some environmental value to add"
    [System.Environment]::SetEnvironmentVariable($variableNameToAdd, $variableValueToAdd, [System.EnvironmentVariableTarget]::Machine)
    [System.Environment]::SetEnvironmentVariable($variableNameToAdd, $variableValueToAdd, [System.EnvironmentVariableTarget]::Process)
    [System.Environment]::SetEnvironmentVariable($variableNameToAdd, $variableValueToAdd, [System.EnvironmentVariableTarget]::User)
    

提交回复
热议问题