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")
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.