Add Windows Permanent PATH Using PowerShell

For the first of the month (October) blog post, I will show you how to add a permanent PATH to Windows environment variables using PowerShell.

Adding an entry to the Windows PATH using the user interface can be annoying because there are so many screens to go over. In yesterday’s post, I showed how to access the environment variables using PowerShell.

In yesterday’s post, I also showed how to add a new PATH using PowerShell; however, when you do, it gets removed when the PowerShell console closes. To make a PATH permanent, we need to write the changes to the registry as you will see below.

Add Path to PATH

In may case, I am going to add the following path to my PATH and make it permanent.

c:\ssh

Let’s get an output of the current PATH using the cmdlet below.

Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name path

Now, I will save the current path to a variable.

$old = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name path).path

Let’s add the new path to the variable

$new  =  "$old;c:\ssh"  

And in the final and last command I will join the two to the PATH

Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name path -Value $new

To view the new path in the PATH run the first cmdlet.

Processing…
Success! You're on the list.

2 Replies to “Add Windows Permanent PATH Using PowerShell”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.