TOC
Summary
On UNIX-like OS, it provide commands that allows you to access environment variables.
Examples are export
and set
…etc.
How to get/set the Environment Variables of Windows on command line?
Prerequisites
- PowerShell v5.1
- .NET Core v3.1
- Windows 10 v21H1
Method
PowerShell is available to access .NET. So, using Environment.GetEnvironment
andEnvironment.SetEnvironment
to get and set the Environment Variables of Windows.
In this post uses the Test1
environment variable as an example.
Get
[Environment]::GetEnvironmentVariable("Test1", "User")
Set (Updating)
[Environment]::SetEnvironmentVariable("Test1", "ABCDEFG", "User")
Set (Deleting)
[Environment]::SetEnvironmentVariable("Test1", "", "User")