To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using:
set NEWVAR=SOMETHING
you are just setting it in the current process space.
According to this page you can use the setx command:
setx NEWVAR SOMETHING
setx is built into Windows 7, but for older versions may only be available if you install the Windows Resource Kit
To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using:
set NEWVAR=SOMETHING
you are just setting it in the current process space.
According to this page you can use the setx command:
setx NEWVAR SOMETHING
setx is built into Windows 7, but for older versions may only be available if you install the Windows Resource Kit
We can also use "setx var variable /M" to set the var to system environment variable level instead of user level.
Note: This command should be run as administrator.
Environment Variable Setting via Command Line
go - How can I set the environment variables in Windows? - Stack Overflow
Add environment property to the profiles in settings.json
Pycharm environment variables
Videos
From this answer, you can set a local environment variable for your shell with Powershell's $env:VARIABLE_NAME.
If I'm understanding your question correctly this should work for you if your objective is to just grab the variable name/value from the current terminal session.
PS C:\> $env:FOO = 'BAR'
PS C:\> docker run -it -e FOO alpine:3.9 /bin/sh
/ # env
HOSTNAME=e1ef1d7393b2
SHLVL=1
HOME=/root
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
FOO=BAR
PWD=/
/ # exit
PS C:\>
An equivalent of unset would be one of the following (thanks to @mklement0 for the suggestion) :
Remove-Item env:\FOO
# suggested by mklement0
null
Create a Powershell script docker_run.ps1
And inside the script, you can define global variables and then use them in the docker run command written at the end of the script.
This way it becomes easy to re-use the command easy to edit as well for any quick changes.
The file would look as below:
$global:ENV1="VALUE1"
$global:ENV2="VALUE2"
docker run -e ENV1=$ENV1 -e ENV2=$ENV2 --name Container_Name Image_Name
And now just run this script inside the CMD as:
powershellpowershell docker_run.ps1
Here’s how I’ve done it many times via command line. Run setx /? at a cmd prompt for all the options. /M makes it a system wide variable.
Ex.
ORACLE_HOME is the variable name.
The C:\ path is the value of the variable.
SETX ORACLE_HOME C:\Oracle\product\11.2.0\instantclient_11_2 /M
Is there a command line I can use to set PC and Server environment variables? I have several I have to type in often. It would be nice to write a script to enter them for me.
In Windows, environment variables can be applied in two ways.
Set modifies the current shell's (the window's) environment values, and the change is available immediately, but it is temporary. The change will not affect other shells that are running, and as soon as you close the shell, the new value is lost until such time as you run set again.
Copycmd> SET ADDR=127.0.0.1
cmd> SET TOKEN=ABCD1234
cmd> SET
setx modifies the value permanently, which affects all future shells, but does not modify the environment of the shells already running. You have to exit the shell and reopen it before the change will be available, but the value will remain modified until you change it again.
Copycmd> setx ADDR "127.0.0.1"
cmd> setx TOKEN "ABCD1234"
cmd> SET
You can try using the set method in a terminal in the following way:
Copyset NODE_HOME=C:\Users\359855\Downloads\node-v14.16.0-win-x64
set PATH=%PATH%;%NODE_HOME%;
Note: After seeing lots of comments about setting environment variables without administrator rights in Windows 10, I think I have found a way. I was not administrator and could use PowerShell.
PowerShell method
You can list all environment variables with: Get-ChildItem Env:.
To get the value of a specific variable: $Env:PATH, where PATH is the name of the variable.
To set a variable: [Environment]::SetEnvironmentVariable("PATH", "C:\TestPath", "User"), the first parameter is the name of the variable, the second is the value, the third is the level of.
There are different ways to work with environment variables and certain quirks with them in PowerShell so consult the link for details.
Old method (no longer available in newer Windows 10 updates, use PowerShell or see other answers)
Go into Settings and click on System.

Then on the left side click About and select System info at the bottom.

In the new Control Panel window that opens, click Advanced system settings on the left.

Now in the new window that comes up, select Environment Variables... at the bottom.

Still the same as ever: It’s in the old-style control panel’s “System” thingy. You can reach it with WinBreak or by right-clicking the Start button.
From there, select “Advanced system settings” → “Environment Variables”.
Or you can do it the hard way and find some other entry point to the old-style control panel, like the Network and Sharing Center or the Desktop folder(!).