← All scripts
POWERSHELL Version 1.0.0

Add System PATH Manager

Quickly add a folder to the Windows System PATH environment variable. Checks whether the folder exists and prevents duplicate entries. Requires administrator privileges.

Source code

SHA-256: 159a5eaef1397a741667d556fae5f7fbe2a7f26685aa1fa275bfed06a75d21d1
# System PATH Manager - ScriptSnatch.com

Write-Host "`nADD TO SYSTEM PATH" -ForegroundColor Cyan
Write-Host "------------------------"

$path = (Read-Host "Enter folder path").Trim().Trim('"')

if (-not (Test-Path -LiteralPath $path -PathType Container)) {
    Write-Host "Folder does not exist." -ForegroundColor Red
    return
}

$path = (Get-Item -LiteralPath $path).FullName.TrimEnd('\')

$current = [Environment]::GetEnvironmentVariable("Path", "Machine")
$entries = @($current -split ';' | Where-Object { $_ })

if ($entries -contains $path) {
    Write-Host "Path already exists." -ForegroundColor Yellow
    return
}

try {
    [Environment]::SetEnvironmentVariable(
        "Path",
        (($entries + $path) -join ';'),
        "Machine"
    )

    Write-Host "Successfully added to System PATH!" -ForegroundColor Green
}
catch {
    Write-Host "Failed. Run PowerShell as Administrator." -ForegroundColor Red
}
Download file

Community reviews

No published reviews yet.

Leave a review

Reviews are moderated. Your email is not displayed publicly.