Skip to content
 
 

Repository files navigation

Windows PATH Repair Tool

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.

What it does

  • Reads the current User and Machine PATH values separately.
  • Removes duplicate entries while preserving the first occurrence and its precedence.
  • Retains currently unreachable entries by default; remove them only with the explicit -RemoveMissingEntries option 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 -Apply is 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.

Project lineage

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.

Before you start

  • 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. PATH order determines which executable Windows selects when more than one tool has the same name.
  • Do not use -Apply if the preview includes a change you do not want. Adjust the input or investigate it first.

Usage

1. Preview the proposed changes (safe default)

From PowerShell in this folder:

.\Windows-Path-Repair-Full.ps1

The 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 -DryRun

2. Apply an approved preview

For both scopes, open PowerShell as Administrator and run:

.\Windows-Path-Repair-Full.ps1 -Apply

The 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.

3. Target one scope when appropriate

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 -Apply

Optional cleanup and known-tool additions

The 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 -RemoveMissingEntries

To 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 -Detailed

Administrator launcher

Double-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.

Backups and recovery

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.

Requirements

  • Windows 10 or Windows 11
  • PowerShell 5.1 or later
  • Administrator privileges only when applying a Machine PATH change

License

This project is licensed under the MIT License. See LICENSE.

About

The Windows PATH Repair Tool is a comprehensive solution for repairing and optimizing your Windows PATH environment variables. It includes an extensive database of potential PATH directories updated for Windows 11 as of April 2025, ensuring all your command-line tools and applications work correctly.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages