Skip to end of banner
Go to start of banner

Create Windows Environment Variables with PowerShell

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

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

  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

# 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')

  • No labels