Powershell Add System Variable

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.

Leave a Comment