1

In my Powershell script I'm setting machine-level environment variables with:

[Environment]::SetEnvironmentVariable("MY_VARIABLE", "MY_VALUE", "Machine")

Inside this same script, I am calling another application that will look for the variable above. Is there a way for me to reload the current session with the variables I created above?

2 Answers 2

3

No but you can also set the environment variables for the current process i.e. $env:MY_VARIABLE = 'MY_VALUE'. Any application you start should inherit the environment variables set in this fashion.

Sign up to request clarification or add additional context in comments.

Comments

0

This should be done manually, and to avoid mistype when load Environment variable value to the current session you could try:

Write-Host $Env:MY_VARIABLE   # should be empty
$Env:MY_VARIABLE = [Environment]::GetEnvironmentVariable("MY_VARIABLE", "User")
Write-Host $Env:MY_VARIABLE`  # should be updated

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.