Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

Update environment variables in Powershell May 20, 2010

Filed under: Powershell,Systems Administration — Rupert Bates @ 9:27 am

To update an environment variable in Powershell in a way that lasts beyond the current session you can use the SetEnvironmentVariable method:

[Environment]::SetEnvironmentVariable(“theVariableToSet”, “theNewValue, “User”)

The final parameter determines the scope of the variable and can be one of Process, User or Machine.

So to add to your path you can use the following:

$path = [environment]::GetEnvironmentVariable(“path”,”User”) + “C:\Program Files\Git\bin;”
[Environment]::SetEnvironmentVariable(“path”, $path, “User”)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s