PowerShell add Windows PATH variable using setx.
Run Powershell as Administrator
setx /M PATH "$Env:PATH;"
To verify
$Env:PATH
NOTE: In Windows 10 unless ‘/m’ is the very first argument rather than the last, the variable is set in the logged-in user’s context not the machine’s.
Remarks
- The Setx command is similar to the UNIX utility SETENV.
- Setx provides the only command-line or programmatic way to directly and permanently set system environment values. System environment variables are manually configurable through Control Panel or through a registry editor. The set command, which is internal to the command interpreter (Cmd.exe), sets user environment variables for the current console window only.
- You can use the setx command to set values for user and system environment variables from one of three sources (modes): Command Line Mode, Registry Mode, or File Mode.
- Setx writes variables to the master environment in the registry. Variables set with setx variables are available in future command windows only, not in the current command window.
- HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE are the only supported hives. REG_DWORD, REG_EXPAND_SZ, REG_SZ, and REG_MULTI_SZ are the valid RegKey data types.
- When you gain access to REG_MULTI_SZ values in the registry, only the first item is extracted and used.
- You cannot use the setx command to remove values that have been added to the local or system environments. You can use set with a variable name and no value to remove a corresponding value from the local environment.
- REG_DWORD registry values are extracted and used in hexadecimal mode.
- File mode supports the parsing of carriage return and line feed (CRLF) text files only.