-- Makinaya bağlı  ethernertin güç korumasını kapatmak içim

# ======================================================
# Disable Ethernet Power Management (Energy Saving)
# Author: ChatGPT
# Purpose: Disable power saving features on all Ethernet adapters
# ======================================================

Write-Host "Ethernet güç yönetimi kapatılıyor..." -ForegroundColor Cyan

# Tüm Ethernet adaptörlerini al (Wi-Fi hariç)
$adapters = Get-NetAdapter | Where-Object { $_.MediaType -eq "802.3" -and $_.Status -eq "Up" }

foreach ($adapter in $adapters) {
    Write-Host "İşleniyor: $($adapter.Name)"

    # 1?? Windows power saving (Device Manager -> Power Management)
    try {
        $pnp = Get-PnpDevice -FriendlyName $adapter.Name -ErrorAction Stop
        $pnpid = $pnp.InstanceId

        $key = "HKLM:\SYSTEM\CurrentControlSet\Enum\$pnpid\Device Parameters\Interrupt Management\MessageSignaledInterruptProperties"
        if (Test-Path $key) {
            Set-ItemProperty -Path $key -Name "MSISupported" -Value 0 -ErrorAction SilentlyContinue
        }

        # Bazı sürücülerde farklı kayıt yolu olabilir:
        $powerKey = "HKLM:\SYSTEM\CurrentControlSet\Enum\$pnpid\Device Parameters"
        if (Test-Path $powerKey) {
            # Bu değer kartın “Allow the computer to turn off this device to save power” kutusunu kaldırır
            Set-ItemProperty -Path $powerKey -Name "PnPCapabilities" -Value 24 -ErrorAction SilentlyContinue
        }
    }
    catch {
        Write-Host "?? $($adapter.Name) için kayıt erişimi başarısız: $($_.Exception.Message)" -ForegroundColor Yellow
    }

    # 2?? Gelişmiş enerji özellikleri (bazı Intel kartlarında)
    try {
        $advProps = Get-NetAdapterAdvancedProperty -Name $adapter.Name -ErrorAction SilentlyContinue
        foreach ($prop in $advProps) {
            if ($prop.DisplayName -match "Energy" -or $prop.DisplayName -match "Power") {
                Write-Host " - Özellik devre dışı: $($prop.DisplayName)"
                Set-NetAdapterAdvancedProperty -Name $adapter.Name -DisplayName $prop.DisplayName -DisplayValue "Off" -NoRestart -ErrorAction SilentlyContinue
            }
        }
    } catch {}

}

Write-Host "Tüm Ethernet adaptörlerinde güç koruma devre dışı bırakıldı ?" -ForegroundColor Green
