I'm trying to set the %systemroot% environment variable in powershell on windows 10. It's not working.
Here's what I've tried and the results:
$env:SystemRoot = "C:\Windows"
echo %SystemRoot%
%SystemRoot%
setx SystemRoot "C:\Windows"
SUCCESS: Specified value was saved.
echo %SystemRoot%
%SystemRoot%What am I doing wrong?
11 Answer
You are mixing up PowerShell and DOS syntax.%SystemRoot% is DOS syntax, the PowerShell syntax is $env:SystemRoot.
The following example will perhaps clarify the difference:
Please note that the change of the value of SystemRoot only applies
to this one PowerShell instance (is not system-wide).
Reference:How To Work with Environment Variables in PowerShell.
1