I would like to introduce a simple powershell script that can read and write environment variables:

Normally I use the Windows GUI and invoke it like so:

rundll32.exe sysdm.cpl,EditEnvironmentVariables

Unfortunately the GUI is broken at 175% zoom. Meanwhile, I found a way to use it anyway with help of the powershell interface of AutoIt.

Set-Location $PSScriptRoot
Import-Module ..\..\Software\Dev\AutoIt\AutoItX
rundll32.exe sysdm.cpl,EditEnvironmentVariables
Start-Sleep 2
Move-AU3Win 'Environment Variables' '' 0 -50 500 1000

You don’t need to do UI automation. You [environment]::SetEnvironmentVariable() and [environment]::GetEnvironmentVariable() methods.

[environment]::SetEnvironmentVariable('VariableName','Value','Machine') # Machine level
[environment]::SetEnvironmentVariable('VariableName','Value','User') # Current User level
[environment]::SetEnvironmentVariable('VariableName','Value','Process') # Current process level


I prefer the GUI, Get-EnvironmentVariable was written while the GUI did not work because the OK button was not visible on screen and there was no way to make it visible with mouse or keyboard. After Get-EnvironmentVariable was written I thought it’s likely easy to make the GUI usable, so I used AutoIt. Dealing with list variables like PATH I think Get-EnvironmentVariable is more convenient than any existing CLI solution.