Is there a way to change the value of an environment variable (system) through powershell? I have only been able to change the value manually and see the change after restarting powershell. Context: We are trying to dynamically set the value of an indirect SSIS configuration and the configuration file is different per environment.
Asked
Active
Viewed 2,925 times
8
-
Related post - [Powershell Add System Variable](https://stackoverflow.com/q/32730544/465053) – RBT Mar 01 '21 at 07:57
1 Answers
11
To set an environment variable at the system level (and make them persistent), you need to use the .Net Framework method [Environment]::SetEnvironmentVariable()
In the current session, you can set them via $env:NAME = VALUE
.
See http://technet.microsoft.com/en-us/library/ff730964.aspx

alroc
- 27,574
- 6
- 51
- 97
-
Thanks for the answer, Lance. Note: If you want to change the environment variable at runtime so that SSIS will use a different configuration, this will not work. You will have to import the configuration file with powershell directly in order to overwrite the package configuration without passing through the environment variable. Not quite sure why this happens. – dirtyw0lf Mar 15 '13 at 02:38