mohsinulhaq
mohsinulhaq

Reputation: 1107

How to revert Powershell PATH variable to the default value

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

Upvotes: 0

Views: 546

Answers (2)

mohamed saeed
mohamed saeed

Reputation: 303

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") 

Upvotes: 0

leeharvey1
leeharvey1

Reputation: 1436

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

Upvotes: 1

Related Questions