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. (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.
...
echo $env:Your_Environment_Variable_Here
Excerpt
name | ChatGPT_answer |
---|
ChatGPT 3.5 Answer
Creating environment variables and assigning values to them in PowerShell is straightforward. You can use theSet-Item
cmdlet to create or modify environment variables. Here's how you can do it:...
[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.