Permanently Changing User Environment Variables

Share |

Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus

13 Free SQL Tools from Idera

Free Ebook: Mastering Powershell

To create or change an environment variable in the user context, use this low-level call:

[environment]::SetEnvironmentVariable('Test', 12,'User')

This environment variable will keep the value until you change it or delete it - even across reboots. So, it can be used for communication between processes or to keep state across reboots. This is how you read the variable:


And to delete the variable, use this line:

[environment]::SetEnvironmentVariable('Test', '','User')

Twitter This Tip! ReTweet this Tip!

Posted Nov 10 2011, 06:00 AM by ps1
Copyright 2012 All rights reserved.