Skip to content

Instantly share code, notes, and snippets.

@fhrddn
Last active April 27, 2025 22:46
Show Gist options
  • Save fhrddn/7a089afcf5760f8c783973fcfa503c53 to your computer and use it in GitHub Desktop.
Save fhrddn/7a089afcf5760f8c783973fcfa503c53 to your computer and use it in GitHub Desktop.
$code = @'
# ==================== ULTIMATE MAINTENANCE & SECURITY SCRIPT (v2024.06) ====================
$ErrorActionPreference = 'Continue'
# -- Admin Check --
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "`n❌ Please RIGHT CLICK and RUN AS ADMINISTRATOR." -ForegroundColor Red
Pause; exit 1
}
Write-Host "`n*** ULTIMATE MAINTENANCE MODE (AUTOMATIC, FULL RDP ACCESS, DAILY RESTART) ***`n" -ForegroundColor Green
# Logging (başlangıç)
$logFile = "$env:ProgramData\ultimate-maintenance-automatic-$env:USERNAME.txt"
try { Start-Transcript -Path $logFile -Append } catch {}
# Fonksiyon: Timeout'lu dış uygulama çalıştırıcı
function RunWithTimeout($file, $args, $timeoutSec) {
try {
Write-Host "Starting: $file $args (Timeout: $timeoutSec sec)"
$proc = Start-Process -FilePath $file -ArgumentList $args -PassThru -WindowStyle Hidden
if ($proc | Wait-Process -Timeout $timeoutSec) {
Write-Host "$file completed."
return $true
} else {
Write-Host "⚠️ $file did NOT finish in $timeoutSec seconds. Skipping..." -ForegroundColor Yellow
try { $proc.Kill() } catch {}
return $false
}
} catch { Write-Host "Process $file error: $_" -ForegroundColor Yellow }
}
# --- RDP FULL PERMIT ---
Write-Host "`n--- === RDP FULL PERMIT === ---`n" -ForegroundColor Magenta
try {
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name "fDenyTSConnections" -Value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
New-NetFirewallRule -DisplayName "Allow RDP" -Direction Inbound -Protocol TCP -LocalPort 3389 -Action Allow -Profile Any -EdgeTraversalPolicy Allow -ErrorAction SilentlyContinue
Set-Service -Name TermService -StartupType Automatic
Start-Service -Name TermService
$nets = Get-NetConnectionProfile | Where-Object {$_.NetworkCategory -ne "Private"}
foreach ($net in $nets) { Set-NetConnectionProfile -InterfaceIndex $net.InterfaceIndex -NetworkCategory Private }
} catch { Write-Host "RDP erişim ayarlarında hata: $_" -ForegroundColor Yellow }
# Defender (RDP engelleri disable)
Write-Host "Windows Defender engelleri RDP için kaldırılıyor..."
try {
Set-MpPreference -AttackSurfaceReductionRules_Actions Disabled
Set-MpPreference -PUAProtection Disabled
Set-MpPreference -AllowNetworkProtectionDownLevel $false
Set-MpPreference -DisableRealtimeMonitoring $true
Set-MpPreference -EnableControlledFolderAccess Disabled
Set-MpPreference -EnableNetworkProtection Disabled
Set-MpPreference -EnableSmartScreen $false
} catch { Write-Host "Defender/ASR ayarları yapılamadı: $_" -ForegroundColor Yellow }
# --- Local Security Policy ---
try { net accounts /lockoutthreshold:0; Write-Host "Lockout threshold set to OFF." } catch { Write-Host "Lockout threshold setting error: $_" -ForegroundColor Yellow }
# --- DNS Flush ---
try { ipconfig /flushdns; Write-Host "DNS cache flushed." } catch { Write-Host "DNS flush error: $_" -ForegroundColor Yellow }
# --- Microsoft Store Update ---
try { RunWithTimeout "winget" "upgrade --source msstore --accept-package-agreements --accept-source-agreements --all" 600 } catch { Write-Host "Microsoft Store update error: $_" -ForegroundColor Yellow }
# --- Windows Update ---
try {
if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
Install-Module PSWindowsUpdate -Force -Scope CurrentUser | Out-Null
Write-Host "PSWindowsUpdate module installed."
}
Import-Module PSWindowsUpdate -Force | Out-Null
RunWithTimeout "pwsh" "-Command `"Get-WindowsUpdate -AcceptAll -Install`"" 1800
RunWithTimeout "pwsh" "-Command `"Get-WindowsUpdate -MicrosoftUpdate -AcceptAll -Install`"" 1800
} catch { Write-Host "Windows Update error: $_" -ForegroundColor Yellow }
# === WINGET: MASS UPDATE ===
Write-Host "`n--- WINGET MASS UPDATE ---`n" -ForegroundColor Cyan
try {
Write-Host "Tüm uygulamalar toplu güncelleniyor..."
RunWithTimeout "winget" "update --all --accept-package-agreements --accept-source-agreements" 1500
} catch { Write-Host "Toplu winget update --all sırasında hata: $_" -ForegroundColor Yellow }
try {
$updatesListJson = winget update --accept-package-agreements --accept-source-agreements --output json 2>$null
$updatesList = $updatesListJson | ConvertFrom-Json
if ($updatesList -and $updatesList.Sources) {
foreach ($pkg in $updatesList.Sources.Packages) {
$id = $pkg.PackageIdentifier
$cur = $pkg.InstalledVersion
$avail = $pkg.AvailableVersion
if (($id) -and ($cur) -and ($avail) -and ($cur -ne $avail)) {
Write-Host "Force update: $($pkg.Name) ($id) $cur → $avail"
RunWithTimeout "winget" "install --id $id --silent --force --accept-package-agreements --accept-source-agreements" 600
}
}
}
} catch { Write-Host "Güncellenemeyen uygulamaları force yüklerken hata: $_" -ForegroundColor Yellow }
# --- Gerekli uygulamalar WINGET ile kuruluyor ---
$appsToInstall = @(
"Microsoft.DotNet.DesktopRuntime.6", "Microsoft.DotNet.DesktopRuntime.7", "Microsoft.DotNet.DesktopRuntime.8", "Microsoft.DotNet.DesktopRuntime.9",
"Microsoft.DotNet.DesktopRuntime.6-x86", "Microsoft.DotNet.DesktopRuntime.7-x86", "Microsoft.DotNet.DesktopRuntime.8-x86", "Microsoft.DotNet.DesktopRuntime.9-x86",
"Microsoft.DotNet.Runtime.6", "Microsoft.DotNet.Runtime.7", "Microsoft.DotNet.Runtime.8", "Microsoft.DotNet.Runtime.9",
"Microsoft.DotNet.Runtime.6-x86", "Microsoft.DotNet.Runtime.7-x86", "Microsoft.DotNet.Runtime.8-x86", "Microsoft.DotNet.Runtime.9-x86",
"Microsoft.DotNet.SDK.6", "Microsoft.DotNet.SDK.7", "Microsoft.DotNet.SDK.8",
"Microsoft.DotNet.SDK.6-x86", "Microsoft.DotNet.SDK.7-x86", "Microsoft.DotNet.SDK.8-x86",
"Giorgiotani.VisualCppRedist.AIO",
"7zip.7zip", "voidtools.Everything", "Notepad++.Notepad++", "Microsoft.Edge", "Google.Chrome", "Microsoft.WindowsTerminal",
"Microsoft.VisualStudioCode", "Foxit.FoxitReader", "Greenshot.Greenshot", "BleachBit.BleachBit", "CodecGuide.K-LiteCodecPack.Mega",
"Zoom.Zoom", "AnyDeskSoftwareGmbH.AnyDesk", "Google.GoogleDrive", "WhatsApp.WhatsApp", "Telegram.TelegramDesktop",
"Mozilla.Thunderbird", "CPUID.CPU-Z", "Microsoft.PowerShell", "RustDesk.RustDesk"
)
foreach ($app in $appsToInstall) {
try {
$installed = winget list --id $app --accept-source-agreements | Select-String $app
if ($installed) { Write-Host "Already installed: $app" -ForegroundColor Cyan; continue }
Write-Host "Installing: $app ..."
RunWithTimeout "winget" "install --id $app --silent --accept-package-agreements --accept-source-agreements" 900
} catch { Write-Host "Install error ($app): $_" -ForegroundColor Yellow }
}
# --- Temizlik işlemleri ---
$cleanupTasks = @(
@{ Desc="Cleaning user temp"; Path="$env:TEMP\*" },
@{ Desc="Cleaning system temp"; Path="C:\Windows\Temp\*" },
@{ Desc="Cleaning Windows Update"; Path="C:\Windows\SoftwareDistribution\Download\*" },
@{ Desc="Cleaning old logs"; Path="C:\Windows\Logs\*" }
)
foreach ($task in $cleanupTasks) {
try {
Write-Host $task.Desc
Remove-Item -Path $task.Path -Force -Recurse -ErrorAction SilentlyContinue
} catch {
Write-
'@
Invoke-Expression $code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment