Powershell – Windows 7 Custom Environment Variable Disappears

environment-variablesms-dospowershell

I am trying to set a custom environment variable in Windows 7, which needs to be done programmatically as it must be set on multiple computers.

I have been testing one a single machine, but When I create it programmatically, it exists for that session (i.e. in DOS when the command window is open, or in Powershell when the ISE is open) – however, when I close the session the variable disappears?

How do I make it permanent?

Thanks,

Ben

Best Answer

for users
wmic environment create name='test', variablevalue='air',username='domain\username'

for computer
wmic environment create name='test', variablevalue='air',username='system'

can work remotely by using the /node: paramter

maybe overkill but

http://blogs.technet.com/b/heyscriptingguy/archive/2010/06/03/hey-scripting-guy-can-i-use-windows-powershell-to-read-a-text-file-and-update-an-environment-variable-on-remote-computers.aspx