Ekran görüntüsü :


Kod: Tümünü seç
<#
.SYNOPSIS
Bir dizini hem Kullanıcı hem de Sistem PATH değişkenlerine ekler.
.DESCRIPTION
Bu betik, yönetici yetkisiyle çalışır. Kullanıcıdan geçerli bir klasör yolu ister
ve bu yolu PATH ortam değişkenine (User ve Machine) ekler.
Eğer yol zaten mevcutsa, ekleme yapmaz.
.NOTES
Yazar: TRWE_2012 tarafından oluşturuldu
Sürüm: 1.0
#>
# ---------- YÖNETİCİ YETKİSİ KONTROLÜ ----------
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "Bu betik yönetici yetkisi gerektiriyor. Kendini yeniden başlatıyor..." -ForegroundColor Yellow
# Yönetici olarak yeniden başlat
Start-Process powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}
# ---------- KULLANICIDAN DİZİN YOLU ALMA ----------
do {
$folderPath = Read-Host -Prompt "PATH'e eklenecek dizinin tam yolunu girin (örn: C:\PSTools)"
if ([string]::IsNullOrWhiteSpace($folderPath)) {
Write-Host "Boş girilemez. Lütfen bir yol girin." -ForegroundColor Red
continue
}
# Sondaki ters bölüyü temizle
$folderPath = $folderPath.TrimEnd('\')
if (Test-Path $folderPath -PathType Container) {
break
} else {
Write-Host "Hata: Belirtilen dizin mevcut değil. Lütfen geçerli bir yol girin." -ForegroundColor Red
}
} while ($true)
# ---------- PATH'E EKLEME FONKSİYONU ----------
function Add-ToPath {
param(
[string]$pathToAdd,
[string]$target # "User" veya "Machine"
)
# Mevcut PATH değerini oku
$currentPath = [Environment]::GetEnvironmentVariable("Path", $target)
# PATH'i noktalı virgül ile ayır ve kontrol et
$pathItems = $currentPath -split ';'
if ($pathItems -contains $pathToAdd) {
Write-Host "Yol zaten $target PATH'inde mevcut: $pathToAdd" -ForegroundColor Yellow
return $false
} else {
$newPath = $currentPath + ";" + $pathToAdd
[Environment]::SetEnvironmentVariable("Path", $newPath, $target)
Write-Host "Yol başarıyla $target PATH'ine eklendi: $pathToAdd" -ForegroundColor Green
return $true
}
}
# ---------- EKLEME İŞLEMİ ----------
Write-Host "`nKullanıcı PATH'ine ekleniyor..." -ForegroundColor Cyan
Add-ToPath -pathToAdd $folderPath -target "User"
Write-Host "`nSistem PATH'ine ekleniyor..." -ForegroundColor Cyan
Add-ToPath -pathToAdd $folderPath -target "Machine"
# ---------- BİTİRME ----------
Write-Host "`nİşlem tamamlandı." -ForegroundColor Green
Write-Host "Not: Yeni PATH ayarlarının geçerli olması için yeni bir komut penceresi (CMD/PowerShell) açmanız gerekecek." -ForegroundColor Cyan
Read-Host "`nÇıkmak için Enter'a basın"
