Skip to main content
Skip table of contents

Create Windows Environment Variables with PowerShell

How to create environment variables and assign values to them with PowerShell.

How to Setup a Environmental Variables

Create a persistent/permanent environmental variable for the current user only.

  1. Open PowerShell as an administrator. (See How to Run PowerShell Scripts)

  2. Enter the following command:

    [System.Environment]::SetEnvironmentVariable("Your_Environment_Variable_Here", "your_value_here", "User")

    • Replace 'Your_Environment_Variable_Here' with the appropriate variable name
      e.g.; CONNECTED_ACU_API_PASSWORD, CONNECTED_ACU_API_VENDOR_KEY, CONNECTED_ACU_API_USER_KEY)

    • Replace 'your_value_here' with the respective values for the variable.

 How to Display / Echo the Value of Environmental Variables

You can check if the environment variable was created with the echo command.

      echo $env:Your_Environment_Variable_Here


[Environment]::SetEnvironmentVariable Syntax

Scope of Environment Variable

  • User Scope: Applies to the current user only.

  • Machine Scope: Applies to all users on the machine.

  • Process Scope: Applies only to the current PowerShell process

Examples

POWERSHELL
# Setting a user-level persistent environment variable
[Environment]::SetEnvironmentVariable('PersistentVar', 'Persistent Value', 'User')

# Setting a machine-level persistent environment variable
[Environment]::SetEnvironmentVariable('PersistentVar', 'Persistent Value', 'Machine')

Related Pages

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.