As above.

I tried (inside powershell terminal with run as admin)


and the variable is only available for that window. If I open another powershell window or restart my PC, the variable is lost.


  • Why don’t you create the system variable through the GUI?
    – Ramhound
    Jul 5 at 2:33

1 Answer 1


Please specify the scope when setting the variable:

Saving environment variables with SetEnvironmentVariable

On Windows, you can specify a scope for the SetEnvironmentVariable method as the third parameter to set the environment variable in that scope. The machine and user scopes both persist outside of the current process, allowing you to save a new or changed environment variable.

[System.Environment]::SetEnvironmentVariable('ResourceGroup','AZ_Resource_Group', 'Machine')
[System.Environment]::SetEnvironmentVariable('ResourceGroup','AZ_Resource_Group', 'User')

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.