0

I have mistakenly replaced the PATH variable instead of appending to it. How do I revert back to the default value of the PATH?

1
  • 6
    How did you overwrite it? If it was just for the current process, it's as easy as exiting the current shell and starting a new one Commented Dec 5, 2020 at 16:23

2 Answers 2

1

If we want to reset your PATH environment variable without restarting your PowerShell session, give this a try:

$Env:Path = [System.Environment]::GetEnvironmentVariables([System.EnvironmentVariableTarget]::Machine).Path + ';' + [System.Environment]::GetEnvironmentVariables([System.EnvironmentVariableTarget]::User).Path
Sign up to request clarification or add additional context in comments.

Comments

0

To get the default current path run the following

($env:PATH).split(";")

if i understand your question that you have by mistake replace the path variable so if you run the command on the last answer it will revert back the fault current path it will not add the default which has been missed

The default path part of it is the default for any windows are:

C:\WINDOWS\system32 C:\WINDOWS C:\WINDOWS\System32\Wbem C:\WINDOWS\System32\WindowsPowerShell\v1.0
C:\Users$user\AppData\Local\Microsoft\WindowsApps

and the other depending on your apps like that

C:\WINDOWS\System32\OpenSSH
C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools\Best Practices Analyzer
C:\Program Files\PuTTY
C:\Program Files\Docker\Docker\resources\bin C:\ProgramData\DockerDesktop\version-bin C:\Program Files\PowerShell\7-preview\preview C:\Users$user\AppData\Local\Microsoft\WindowsApps C:\Users$user\AppData\Local\Programs\Fiddler C:\Users$user\AppData\Local\Microsoft\WindowsApps C:\Program Files (x86)\OpenVPN\bin C:\Users$user\AppData\Local\GitHubDesktop\bin C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static

you can search what is the default PowerShell path for each program you have

To add a new path

$INCLUDE = "C:\tmp"
$OLDPATH = [System.Environment]::GetEnvironmentVariable('PATH','machine')
$NEWPATH = "$OLDPATH;$INCLUDE"
[Environment]::SetEnvironmentVariable("PATH", "$NEWPATH", "Machine") 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.