Reputation: 5897
I want to use variables over PowerShell instances away. (I know that global variables are not nice) Is this the best way to define a variable over instances in PowerShell? Other ideas? ($global:variable is not over PowerShell instances away)
[Environment]::SetEnvironmentVariable("TestVariable", "Test value.", "User")
[Environment]::GetEnvironmentVariable("TestVariable","User")
Upvotes: 1
Views: 1455
Reputation: 201692
Yes. Other options would be to:
But adding a user environment variable is also a good way to go and the way you suggest is what is needed for the environment changes to survive exiting the current PowerShell session.
Upvotes: 4