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
[environment]::SetEnvironmentVariable('Path')
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.