Trying to set environment variables in windows powershell

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?

1

1 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:

enter image description here

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like