Ask Your Question

Windows Environment Variables after Exec Command

asked 2013-05-13 08:17:02 -0600

louis gravatar image


Is it possible to set/add environment variables with Puppet. Let's say the %PATH% environment variable.

edit retag flag offensive close merge delete


Are you asking whether it's possible to set custom environment variables for a given Exec resource, or globally change environment variables?

fiddyspence gravatar imagefiddyspence ( 2013-05-13 09:26:06 -0600 )edit

Both of them if possible

louis gravatar imagelouis ( 2013-05-13 09:42:14 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2013-05-19 15:51:54 -0600

louis gravatar image

Not sure why. But it seems that Puppet was adding their own directories to the PATH. I used the following script to be executed with powershell.

$nodistPath = ";C:\Program Files (x86)\Git\bin"
$actualPath =[Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Machine)
Write-Host "System Path = $actualPath "
$actualPath = $actualPath + $nodistPath
Write-Host "Modified Path = $actualPath "
edit flag offensive delete link more

answered 2013-05-13 19:43:26 -0600

This can be done using the setx command on windows. setx with a /m switch will set the machine path. I believe this won't take effect until you initiate a new session (ie close and re-open cmd) or explorer.

You can use an exec resource. You may need to cmd /c setx. Or you can do this via powershell provider. Or via the registry- HKLM\System\CurrentControlSet\Control\Session Manager\Environment'

Or a combination of both is something I might try-

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-05-13 08:17:02 -0600

Seen: 1,078 times

Last updated: May 19 '13