Excerpt |
---|
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.
Open PowerShell as an administrator, then enter . (See How to Run PowerShell Scripts)
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 .
echo $env:Your_Environment_Variable_Here
Repeat the process for EACH of the necessary environment variables to run the code (CONNECTED_ACU_API_PASSWORD, CONNECTED_ACU_API_VENDOR_KEY, CONNECTED_ACU_API_USER_KEY).
...
hidden | true |
---|---|
name | ChatGPT_answer |
ChatGPT 3.5 Answer
...
...
[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
Code Block | ||
---|---|---|
| ||
# |
...
Setting a user-level |
...
persistent environment variable |
...
[Environment]::SetEnvironmentVariable('PersistentVar', 'Persistent Value', 'User') # |
...
Setting |
...
Replace "MY_VARIABLE"
with the name of your variable and "my_value"
with the desired value.
...
a machine-level persistent environment variable
[Environment]::SetEnvironmentVariable('PersistentVar', 'Persistent Value', 'Machine') |
Related Pages
Excerpt | ||||
---|---|---|---|---|
| ||||
Internal_Note
|
Code Block |
---|
$env:TEMP_VAR = "temp_value"
|
This variable will not persist after the PowerShell session ends.