| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| param (
|
| [Parameter(Mandatory=$true, HelpMessage="Caminho a remover do PATH")]
|
| [string[]]$PathsToRemove
|
| )
|
|
|
|
|
| $currentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
|
| if (-not $currentPath) {
|
| Write-Error "Não foi possível obter o PATH do utilizador ou o PATH está vazio."
|
| exit
|
| }
|
|
|
| $pathList = $currentPath -split ";" | Where-Object { $_ -ne "" }
|
| $originalCount = $pathList.Count
|
| $newPathList = @()
|
|
|
|
|
| $cleanRemovals = $PathsToRemove | ForEach-Object { $_.Trim().Trim('"').TrimEnd('\') }
|
|
|
| foreach ($p in $pathList) {
|
| $cleanP = $p.Trim().TrimEnd('\')
|
|
|
|
|
| $match = $false
|
| foreach ($rem in $cleanRemovals) {
|
| if ($cleanP -ieq $rem) {
|
| $match = $true
|
| break
|
| }
|
| }
|
|
|
| if (-not $match) {
|
| $newPathList += $p
|
| } else {
|
| Write-Host "🗑️ A remover: $p" -ForegroundColor Yellow
|
| }
|
| }
|
|
|
| $removedCount = $originalCount - $newPathList.Count
|
|
|
| if ($removedCount -gt 0) {
|
|
|
| $updatedPath = $newPathList -join ";"
|
|
|
|
|
| [Environment]::SetEnvironmentVariable("PATH", $updatedPath, "User")
|
|
|
|
|
| $env:PATH = [Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + $updatedPath
|
|
|
| Write-Host "`n✨ Sucesso! $removedCount caminho(s) removido(s) do PATH permanentemente." -ForegroundColor Green
|
| Write-Host "📢 Nota: Novas consolas refletirão a mudança. A sessão atual foi atualizada."
|
| } else {
|
| Write-Host "`nNada a remover. Os caminhos indicados não foram encontrados no PATH do utilizador." -ForegroundColor Gray
|
| }
|
|
|