Ekran görüntüsü :

Kod İçeriği : ( servis_yonetim_v3.5.6.ps1 )
Kod: Tümünü seç
# ============================================================
# SERVIS YONETIM ARACI v2.2 (Geliştirilmiş)
# Windows PowerShell Versiyonu (PS 5.1 ve 7.x Uyumlu)
# ============================================================
# Türkçe karakter desteği
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
# ============================================================
# YÖNETİCİ KONTROLÜ
# ============================================================
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal(
[Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "UYARI: Bu betik Yönetici (Administrator) yetkisi gerektirir!" -ForegroundColor Yellow
Write-Host "PowerShell'i 'Yönetici olarak çalıştır' seçeneği ile açın." -ForegroundColor Yellow
Write-Host ""
Read-Host "Devam etmek için ENTER..."
exit 1
}
# ============================================================
# YARDIMCI FONKSİYONLAR
# ============================================================
# Çıkış fonksiyonu
function Exit-Script {
param([int]$Code = 0)
Write-Host ""
Write-Host "Çıkılıyor..." -ForegroundColor Yellow
Read-Host "ENTER..."
exit $Code
}
# Başlık yazdır
function Show-Header {
Clear-Host
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " Servis Yönetim Aracı v2.2 (Windows)" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
}
# Servis durumunu özet göster
function Show-ServiceStatus {
param([string]$ServiceName)
try {
$service = Get-Service -Name $ServiceName -ErrorAction Stop
$cimService = Get-CimInstance -ClassName Win32_Service -Filter "Name='$ServiceName'" -ErrorAction Stop
Write-Host "--- Servis Bilgisi ---" -ForegroundColor Cyan
Write-Host "Ad : $($service.DisplayName)" -ForegroundColor White
Write-Host "Kısa Ad : $($service.Name)" -ForegroundColor Gray
Write-Host -NoNewline "Aktif durum : "
if ($service.Status -eq "Running") {
Write-Host "Çalışıyor" -ForegroundColor Green
} else {
Write-Host "Çalışmıyor ($($service.Status))" -ForegroundColor Red
}
Write-Host -NoNewline "Başlatma : "
switch ($cimService.StartMode) {
"Automatic" { Write-Host "Otomatik (Automatic)" -ForegroundColor Green }
"Auto" { Write-Host "Otomatik (Auto)" -ForegroundColor Green }
"Manual" { Write-Host "Elle (Manual)" -ForegroundColor Yellow }
"Disabled" { Write-Host "Devre Dışı (Disabled)" -ForegroundColor Red }
default { Write-Host $cimService.StartMode -ForegroundColor Yellow }
}
Write-Host ""
} catch {
Write-Host "HATA: Servis bulunamadı -> $ServiceName" -ForegroundColor Red
Write-Host ""
}
}
# İstatistikleri hesapla ve göster
function Show-Statistics {
param([array]$AllServices)
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " SERVİS İSTATİSTİKLERİ" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
$totalCount = $AllServices.Count
# Durum bazlı sayılar
$runningCount = ($AllServices | Where-Object { $_.State -eq "Running" }).Count
$stoppedCount = $totalCount - $runningCount
# Başlatma türü bazlı sayılar (StartMode: Automatic/Auto, Manual, Disabled)
$autoCount = ($AllServices | Where-Object { $_.StartMode -in @("Automatic", "Auto") }).Count
$manualCount = ($AllServices | Where-Object { $_.StartMode -eq "Manual" }).Count
$disabledCount = ($AllServices | Where-Object { $_.StartMode -eq "Disabled" }).Count
$otherCount = $totalCount - $autoCount - $manualCount - $disabledCount
Write-Host ""
Write-Host "TOPLAM SERVİS SAYISI : $totalCount" -ForegroundColor Green
Write-Host ""
Write-Host "--- Durum Bazlı Dağılım ---" -ForegroundColor Yellow
Write-Host " Çalışan (Running) : $runningCount" -ForegroundColor Green
Write-Host " Durdurulmuş (Stopped) : $stoppedCount" -ForegroundColor Red
Write-Host ""
Write-Host "--- Başlatma Türü Bazlı Dağılım ---" -ForegroundColor Yellow
Write-Host " Otomatik (Auto/Automatic) : $autoCount" -ForegroundColor Green
Write-Host " Elle (Manual) : $manualCount" -ForegroundColor Yellow
Write-Host " Devre Dışı (Disabled) : $disabledCount" -ForegroundColor Red
if ($otherCount -gt 0) {
Write-Host " Diğer (Boot/System) : $otherCount" -ForegroundColor Gray
}
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
}
# Servisleri listele (GELİŞTİRİLDİ)
function Show-ServiceList {
Show-Header
Write-Host "--- Sistemdeki Servisler ---" -ForegroundColor Cyan
Write-Host ""
Write-Host "Filtre seçin:" -ForegroundColor Cyan
Write-Host " 1 - Tüm servisler" -ForegroundColor White
Write-Host " 2 - Sadece çalışan servisler" -ForegroundColor Green
Write-Host " 3 - Sadece durdurulmuş servisler" -ForegroundColor Red
Write-Host " 4 - Sadece otomatik başlayanlar (Automatic)" -ForegroundColor Green
Write-Host " 5 - Sadece devre dışı olanlar (Disabled)" -ForegroundColor Yellow
Write-Host " 6 - Geri dön (menü)" -ForegroundColor White
Write-Host ""
$filter = Read-Host "Seçiminiz [1-6]"
Write-Host ""
# Tüm servisleri bir kez al (performans için)
$allServices = Get-CimInstance -ClassName Win32_Service -ErrorAction SilentlyContinue | Sort-Object Name
if ($null -eq $allServices -or $allServices.Count -eq 0) {
Write-Host "HATA: Servisler alınamadı." -ForegroundColor Red
Read-Host "Devam etmek için ENTER..."
return
}
$filteredServices = @()
$title = ""
switch ($filter) {
"1" {
$title = "Tüm Servisler"
$filteredServices = $allServices
}
"2" {
$title = "Çalışan Servisler"
$filteredServices = $allServices | Where-Object { $_.State -eq "Running" }
}
"3" {
$title = "Durdurulmuş Servisler"
$filteredServices = $allServices | Where-Object { $_.State -ne "Running" }
}
"4" {
$title = "Otomatik Başlayan Servisler (Automatic/Auto)"
# DÜZELTME: Hem "Automatic" hem "Auto" değerlerini yakala
$filteredServices = $allServices | Where-Object { $_.StartMode -in @("Automatic", "Auto") }
}
"5" {
$title = "Devre Dışı Servisler (Disabled)"
$filteredServices = $allServices | Where-Object { $_.StartMode -eq "Disabled" }
}
"6" {
return
}
default {
Write-Host "Geçersiz seçim." -ForegroundColor Red
Read-Host "Devam etmek için ENTER..."
return
}
}
# Başlık
Write-Host "--- $title ---" -ForegroundColor Cyan
Write-Host ""
# Servisleri listele (manuel formatlama ile)
$count = 0
foreach ($svc in $filteredServices) {
$count++
$statusColor = if ($svc.State -eq "Running") { "Green" } else { "Red" }
$statusText = if ($svc.State -eq "Running") { "Çalışıyor" } else { "Durdurulmuş" }
# Başlatma türü rengi
$startColor = switch ($svc.StartMode) {
{ $_ -in @("Automatic", "Auto") } { "Green" }
"Manual" { "Yellow" }
"Disabled" { "Red" }
default { "Gray" }
}
$startText = switch ($svc.StartMode) {
{ $_ -in @("Automatic", "Auto") } { "Otomatik" }
"Manual" { "Elle" }
"Disabled" { "Devre Dışı" }
default { $svc.StartMode }
}
# Formatlı çıktı
$line = "{0,-3} {1,-40} {2,-15} {3}" -f $count, $svc.Name, $statusText, $startText
Write-Host $line -ForegroundColor White
}
Write-Host ""
Write-Host "Listelenen servis sayısı: $count" -ForegroundColor Yellow
# İstatistikleri göster (sadece "Tüm servisler" seçildiğinde veya her durumda)
if ($filter -eq "1") {
Show-Statistics -AllServices $allServices
} else {
# Filtreli görünümde de genel istatistikleri göster
Write-Host ""
Write-Host "(Genel istatistikler için '1 - Tüm servisler' seçeneğini kullanın)" -ForegroundColor Gray
}
Read-Host "Devam etmek için ENTER..."
}
# ============================================================
# ANA MENÜ
# ============================================================
while ($true) {
Show-Header
Write-Host "--- Ana Menü ---" -ForegroundColor Cyan
Write-Host " 1 - Servisleri Listele" -ForegroundColor White
Write-Host " 2 - Servis Yönet (Start/Stop/Enable/Disable)" -ForegroundColor White
Write-Host " 3 - Çıkış" -ForegroundColor White
Write-Host ""
$mainChoice = Read-Host "Seçiminiz [1-3]"
switch ($mainChoice) {
"1" {
Show-ServiceList
}
"2" {
Show-Header
# Servis adı al
$serviceName = Read-Host "Servis adını girin (örnek: Spooler, wuauserv)"
# Boş giriş kontrolü
if ([string]::IsNullOrWhiteSpace($serviceName)) {
Write-Host "Boş giriş. İşlem iptal edildi." -ForegroundColor Yellow
continue
}
# Servis var mı kontrolü
try {
$service = Get-Service -Name $serviceName -ErrorAction Stop
} catch {
Write-Host "HATA: Servis bulunamadı -> $serviceName" -ForegroundColor Red
Write-Host ""
Read-Host "Devam etmek için ENTER..."
continue
}
Write-Host ""
Show-ServiceStatus -ServiceName $serviceName
# İşlem menüsü
Write-Host "--- İşlem Seçin ---" -ForegroundColor Cyan
Write-Host " 1 - Başlat (Start)" -ForegroundColor Green
Write-Host " 2 - Durdur (Stop)" -ForegroundColor Red
Write-Host " 3 - Otomatik (Automatic)" -ForegroundColor Green
Write-Host " 4 - Elle (Manual)" -ForegroundColor Yellow
Write-Host " 5 - Devre Dışı (Disabled)" -ForegroundColor Red
Write-Host " 6 - Geri dön" -ForegroundColor White
Write-Host ""
$choice = Read-Host "Seçiminiz [1-6]"
switch ($choice) {
"1" { $action = "Start" }
"2" { $action = "Stop" }
"3" { $action = "Automatic" }
"4" { $action = "Manual" }
"5" { $action = "Disabled" }
"6" { continue }
default {
Write-Host "Geçersiz seçim." -ForegroundColor Red
Read-Host "Devam etmek için ENTER..."
continue
}
}
# Onay
Write-Host ""
Write-Host "İşlem : $action" -ForegroundColor Yellow
Write-Host "Servis : $serviceName" -ForegroundColor Yellow
Write-Host ""
$confirm = Read-Host "Devam edilsin mi? (e/h)"
if ($confirm -ne "e" -and $confirm -ne "E") {
Write-Host "İşlem iptal edildi." -ForegroundColor Yellow
Read-Host "Devam etmek için ENTER..."
continue
}
# İşlemi uygula
Write-Host ""
try {
if ($action -eq "Start") {
Start-Service -Name $serviceName -ErrorAction Stop
Write-Host "İşlem başarıyla tamamlandı." -ForegroundColor Green
} elseif ($action -eq "Stop") {
Stop-Service -Name $serviceName -Force -ErrorAction Stop
Write-Host "İşlem başarıyla tamamlandı." -ForegroundColor Green
} elseif ($action -in @("Automatic", "Manual", "Disabled")) {
Set-Service -Name $serviceName -StartupType $action -ErrorAction Stop
Write-Host "İşlem başarıyla tamamlandı." -ForegroundColor Green
}
Write-Host ""
Show-ServiceStatus -ServiceName $serviceName
} catch {
Write-Host "HATA: İşlem başarısız oldu." -ForegroundColor Red
Write-Host "Detay: $($_.Exception.Message)" -ForegroundColor Red
}
Read-Host "Devam etmek için ENTER..."
}
"3" {
Exit-Script -Code 0
}
default {
Write-Host "Geçersiz seçim." -ForegroundColor Red
Start-Sleep -Seconds 1
}
}
}
