Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Powershell and Environmental Variables

$
0
0

Hello PowerShell Community.

 

I am working on a script and have made an observation while setting some environmental variables. I would like to get some insight on why it works this way and how to work around the issue.

 

I am using a psremoting session to set some environmental variables on the remote system.
I set the variable using .net. The powershell session has been elevated and running as admin.

[Environment]::SetEnvironmentVariable("TestVariableName", "My Value", "Machine") 

After the variable has been set, I run the get-childitem env:
I do not see the variable that i had created.

I opened cmd to double check and found the variable.
I opened a powershell session (without elevation) and i also see the variable.
I opened a Powershell session (with elevation) and the variable is there.

My assumption is that the powershell session grabs the environmental variables during
loading and will not see the variables until a new session has been started.

I guess i envision there being a way to direct powershell to reload the variables?

Has anyone  found a way to reload the environmental variables without starting a new powershell session?

At this point, I think that it might be better to go back and just create some reg keys to keep track of the script.

 

All input welcomed. 

 

Thank you.

 

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles