Windows – How to edit users PATH environment variable remotely in Windows

environment-variableswindows

Wondering what tools are available to remotely edit (find and replace actually) the PATH environment variable on all users workstations across the enterprise? We do use SCCM (formerly SMS), but I don't know if that provides the capability to do that. Is this possible with Powershell maybe?

Best Answer

I'd caution you about doing what Nick O'Neil suggests insofar as just blindly overwriting the PATH variable in the registry of all your client computers is likely to cause problems.

A quickie one-liner for a search-and-replace on a literal string in PowerShell would be (long line wrapped for readability-- this is all a single line):

Set-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path -value ( (Get-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path).Path -replace "OLD STRING", "NEW STRING")

You could run that as an Active Directory Startup Script on the affected computers. You could even get fancy and put some kind of flag in the registry (join the computer to a group that's denied rights to apply the GPO again, etc) to make the script only run once per computer.