A conservative Windows PowerShell tool for inspecting and repairing User and Machine PATH values. It is designed to make a reviewable, reversible change—not to guess at every directory on a computer that might contain a tool.
- Reads the current User and Machine
PATHvalues separately. - Removes duplicate entries while preserving the first occurrence and its precedence.
- Retains currently unreachable entries by default; remove them only with the explicit
-RemoveMissingEntriesoption after reviewing the preview. - Adds required Windows directories and, only when requested, a small set of verified well-known tool directories.
- Creates a timestamped JSON backup before any write, verifies each persisted write, and automatically rolls back an earlier scope if a later write or verification fails.
- Shows a complete change preview by default. Nothing is written until
-Applyis supplied.
The supported entry point is Windows-Path-Repair-Full.ps1. Windows-PATH-Repair.ps1 is retained only as a safe compatibility wrapper for existing bookmarks; new usage should call the canonical script directly.
This repository is a safety-focused fork of the original clarboncy/WindowsPathFix project. The fork keeps the original tool's purpose while adding preview-first operation, bounded discovery, verified writes, rollback, recovery, and automated tests.
- Close any command prompts that must use the repaired value, then open a new one after applying changes.
- A Machine PATH change needs an elevated PowerShell session. A User-only preview does not.
- Read the preview carefully.
PATHorder determines which executable Windows selects when more than one tool has the same name. - Do not use
-Applyif the preview includes a change you do not want. Adjust the input or investigate it first.
From PowerShell in this folder:
.\Windows-Path-Repair-Full.ps1The script reports proposed removals and additions for the selected scopes. It does not alter either environment variable or create backup files in preview mode.
-DryRun is the explicit form of the same safe preview mode:
.\Windows-Path-Repair-Full.ps1 -DryRunFor both scopes, open PowerShell as Administrator and run:
.\Windows-Path-Repair-Full.ps1 -ApplyThe script performs its elevation preflight before changing anything. It creates a backup before applying an approved update, verifies the persisted value after each write, and rolls back any earlier scope written by this run if a later write or verification fails.
Use the scope options shown by the script help to avoid changing the other scope. For example, the supported User-only and Machine-only modes are:
.\Windows-Path-Repair-Full.ps1 -UserPathOnly
.\Windows-Path-Repair-Full.ps1 -SystemPathOnly-UserPathOnly and -SystemPathOnly are mutually exclusive; do not supply them together. Omit both to preview or apply both scopes.
Add -Apply only after reviewing that scope's preview:
.\Windows-Path-Repair-Full.ps1 -UserPathOnly -ApplyThe safe default keeps entries that are currently unavailable, such as a disconnected network share. To explicitly remove those entries, preview with -RemoveMissingEntries, then repeat the exact command with -Apply only if the removals are correct.
.\Windows-Path-Repair-Full.ps1 -UserPathOnly -RemoveMissingEntriesTo consider the bounded list of verified tool directories (Git, Node.js, .NET, Chocolatey, npm, Scoop, and PowerShell), use -AddKnownToolPaths. This is opt-in and does not perform a recursive disk scan.
The tool refuses to write an empty PATH unless -AllowEmptyPath is supplied. It also requires -AllowLongPath for a persistent PATH longer than 2,048 characters, and rejects values longer than 32,767 characters.
Run the following to see the full, current parameter reference:
Get-Help .\Windows-Path-Repair-Full.ps1 -DetailedDouble-click Run-PATH-Repair-Admin.bat to open an elevated PowerShell session with a preview of the canonical script. It does not apply changes automatically. Review the result, then rerun the command in that elevated window with -Apply if it is correct.
Every apply operation creates a timestamped JSON backup under %USERPROFILE%\PathBackups before modifying PATH. Keep the backup until you have opened a new terminal and confirmed that your required commands resolve correctly. The backup contains the exact original User and Machine values, and the script automatically rolls back changes from the current run if a later write or read-back verification fails.
To preview a backup restore, run:
.\Windows-Path-Repair-Full.ps1 -RestoreBackup "$env:USERPROFILE\PathBackups\PATH-backup-YYYYMMDD-HHMMSS.json"After reviewing the preview, add -Apply. Restoring Machine scope requires an elevated PowerShell session and creates a new pre-restore backup first.
- Windows 10 or Windows 11
- PowerShell 5.1 or later
- Administrator privileges only when applying a Machine PATH change
This project is licensed under the MIT License. See LICENSE.