Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing lines from Windows path variable

Let's say this is what my Windows system PATH looks like:

C:\oracle\product\11.2.0\32bit\client_1\bin;C:\oracle\product\11.2.0\64bit\client_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\

How would I remove that very first entry and add it to the end of the list? I know you can use setx for this but I would rather do this using PowerShell.

like image 403
Chris Avatar asked Feb 18 '26 12:02

Chris


1 Answers

# Split the existing path into the 1st entry and the rest.
$first, $rest = $env:Path -split ';'

# Rebuild the path with the first entry appended.
$env:Path = ($rest + $first) -join ';'

# To make this change persistent for the current user, 
# an extra step is needed:
[Environment]::SetEnvironmentVariable('Path', $env:Path, 'User')
like image 52
mklement0 Avatar answered Feb 20 '26 02:02

mklement0