| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| param (
|
| [Parameter(Mandatory=$true, HelpMessage="Caminho a adicionar ao PATH")]
|
| [string[]]$NewPaths
|
| )
|
|
|
|
|
| $currentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
|
| $pathList = $currentPath -split ";" | Where-Object { $_ -ne "" }
|
|
|
| $addedCount = 0
|
|
|
| foreach ($p in $NewPaths) {
|
|
|
| $cleanPath = $p.Trim().Trim('"')
|
|
|
| if (-not (Test-Path $cleanPath)) {
|
| Write-Warning "O caminho não existe: $cleanPath"
|
| continue
|
| }
|
|
|
|
|
| if ($pathList -inotcontains $cleanPath) {
|
| $pathList += $cleanPath
|
| $addedCount++
|
| Write-Host "✅ A adicionar: $cleanPath" -ForegroundColor Cyan
|
| } else {
|
| Write-Host "ℹ️ Já existe no PATH: $cleanPath" -ForegroundColor Yellow
|
| }
|
| }
|
|
|
| if ($addedCount -gt 0) {
|
|
|
| $updatedPath = $pathList -join ";"
|
|
|
|
|
| [Environment]::SetEnvironmentVariable("PATH", $updatedPath, "User")
|
|
|
|
|
| $env:PATH = [Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + $updatedPath
|
|
|
| Write-Host "`n✨ Sucesso! $addedCount caminho(s) adicionado(s) ao PATH permanentemente." -ForegroundColor Green
|
| Write-Host "📢 Nota: Novas consolas terão o PATH atualizado. A sessão atual foi atualizada para este processo."
|
| } else {
|
| Write-Host "`nNada a alterar. O PATH já contém os caminhos indicados." -ForegroundColor Gray
|
| }
|
|
|