Bu açılan forum konusunda, denenmesi gerçek sistem'de riskli betiklerin sanal işletim sisteminde denen ve olumlu sonuçlanan betiklere yer verilecektir.Eğer betik başarılı ise ve canlı sistem'de sistem'e sorun verdirmemişse, buradan nihai kararlı sürümü yayınlacak...(forum'a alt mesaj şeklinde yeniden düzenlenecek)
İlk betiğimiz : GuncellemeKur.ps1
KOD İÇERİK AÇIKLAMASI :
Kod: Tümünü seç
# =====================================================================
# Otomatik Windows Update (.msu ve .cab) Kurulum Betiği
# Windows 11 / 10 / 8.1 / 7 Uyumlu
# =====================================================================
# 1. Yönetici Yetkisi Kontrolü
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Warning "HATA: Bu betik güncelleme kuracağı için YÖNETİCİ olarak çalıştırılmalıdır!"
Write-Host "Lütfen PowerShell'i Yönetici olarak açıp tekrar deneyin." -ForegroundColor Cyan
Read-Host "Çıkmak için Enter'a basın"
exit
}
# 2. Hedef Dizini Belirleme (Betik ile aynı klasör)
$TargetDir = $PSScriptRoot
if (-not $TargetDir) { $TargetDir = Get-Location }
# 3. Dosyaları Alma ve Sıralama (.cab ve .msu)
$UpdateFiles = @()
$UpdateFiles += Get-ChildItem -Path $TargetDir -Filter *.msu -File
$UpdateFiles += Get-ChildItem -Path $TargetDir -Filter *.cab -File
# İsimlere göre sırala (isteğe bağlı, ama düzenli kurmak için iyi olur)
$UpdateFiles = $UpdateFiles | Sort-Object Name
if ($UpdateFiles.Count -eq 0) {
Write-Host "Bu klasörde kurulum için .msu veya .cab dosyası bulunamadı." -ForegroundColor Yellow
Read-Host "Çıkmak için Enter'a basın"
exit
}
# 4. Kurulum Döngüsü
Write-Host "======================================================" -ForegroundColor DarkGray
Write-Host " Toplam $($UpdateFiles.Count) güncelleme bulunacak ve sırayla kurulacak." -ForegroundColor Green
Write-Host "======================================================" -ForegroundColor DarkGray
$SuccessCount = 0
$FailCount = 0
$RebootRequired = $false
foreach ($File in $UpdateFiles) {
Write-Host "`n[$($SuccessCount + $FailCount + 1)/$($UpdateFiles.Count)] Kuruluyor: $($File.Name)" -ForegroundColor Cyan
$ExitCode = $null
try {
if ($File.Extension.ToLower() -eq '.msu') {
# .msu dosyaları wusa ile kurulur
$Args = "`"$($File.FullName)`" /quiet /norestart"
$Process = Start-Process -FilePath "wusa.exe" -ArgumentList $Args -Wait -PassThru -WindowStyle Hidden
$ExitCode = $Process.ExitCode
}
elseif ($File.Extension.ToLower() -eq '.cab') {
# .cab dosyaları DISM ile kurulur (Görselinizdeki yöntem)
$Args = "/online /add-package /packagepath:`"$($File.FullName)`" /quiet /norestart"
$Process = Start-Process -FilePath "dism.exe" -ArgumentList $Args -Wait -PassThru -WindowStyle Hidden
$ExitCode = $Process.ExitCode
}
# Çıkış Kodlarına Göre İşlem
if ($ExitCode -eq 0) {
Write-Host " -> BAŞARILI" -ForegroundColor Green
$SuccessCount++
}
elseif ($ExitCode -eq 3010) {
Write-Host " -> BAŞARILI (Yeniden başlatma gerekiyor)" -ForegroundColor Yellow
$SuccessCount++
$RebootRequired = $true
}
elseif ($ExitCode -eq 2359302) {
Write-Host " -> ATLANDI (Bu güncelleme zaten yüklü veya uygunsuz)" -ForegroundColor DarkYellow
$SuccessCount++ # Zaten yüklü olduğu için hata saymayacağız
}
else {
Write-Host " -> HATA! Çıkış Kodu: $ExitCode" -ForegroundColor Red
$FailCount++
}
}
catch {
Write-Host " -> KRİTİK HATA: $($_.Exception.Message)" -ForegroundColor Red
$FailCount++
}
}
# 5. Sonuç Raporu
Write-Host "`n======================================================" -ForegroundColor DarkGray
Write-Host " KURULUM RAPORU" -ForegroundColor White
Write-Host "======================================================" -ForegroundColor DarkGray
Write-Host " Başarılı / Atlanan : $SuccessCount" -ForegroundColor Green
Write-Host " Başarısız : $FailCount" -ForegroundColor Red
if ($RebootRequired) {
Write-Host " DURUM: Güncellemelerin tam etkili olması için sistemi yeniden başlatmanız önerilir." -ForegroundColor Yellow
}
Read-Host "`nİşlemi tamamlamak için Enter'a basın"Bu betik yıllar önce sordum.net web sitesinden aldığım bir ekran görüntüsünden ilham alınarak oluşturuldu/dizayn edildi.

Bu betik:
.msu dosyaları için standart wusa.exe aracını kullanır.
.cab dosyaları için görseldeki gibi dism.exe aracını kullanır.
Her dosya kurulumunu bekler (sıralı kurulum).
Hataları ve yeniden başlatma gereksinimlerini (Error Code 3010) yakalar.
Önemli: Güncellemeleri kurmak her zaman Yönetici (Administrator) yetkisi gerektirir. Betik bunu başlangıçta kontrol eder.
Nasıl Kullanılır?
Güncelleme dosyalarınızı (.msu ve .cab) tek bir klasöre kopyalayın (Örn: C:\Guncellemeler).
Not Defteri (Notepad) veya VS Code açın.
Yukarıdaki kodu yapıştırın.
Dosyayı GuncellemeKur.ps1 adıyla kaydedin (Kayıt türünün "Tüm Dosyalar" olduğundan emin olun).
Bu .ps1 dosyasını güncelleme klasörünün içine atın.
Dosyaya sağ tıklayıp "PowerShell ile çalıştır" yapın. (Veya PowerShell'i Yönetici olarak açıp .\GuncellemeKur.ps1 yazın).
Betikteki Önemli Detaylar:
/quiet /norestart:
Güncellemeler arka planda sessizce kurulur ve işletim sistemi kurulum bitince kendi kendine yeniden başlamaz (kullanıcıyı sisteminden etmez).
Error Code 3010:
Windows Update'lerin en meşhur kodudur. Anlamı "Kurulum başarılı ama değişikliklerin aktif olması için restart lazım". Betik bunu hata olarak saymaz, sarı renkle uyarır.
Error Code 2359302:
"Not Applicable". Yani o güncelleme zaten sisteminizde kurulu veya işletim sistemi sürümünüz bu güncellemeyi kabul etmiyor. Betik bunu atlar.
Sıralama (Sort-Object Name):
Önce .cab dosyaları sonra .msu dosyaları karışmasın diye alfabetik sıraya dizer. Bazen güncellemeler birbirinin bağımlısı olduğu için sıralı kurmak hataları önler.
NOT :
Powershell hata verirse aşağıdaki powershell sağ menü betiğini kullanın.(ben şuan kullanıyorum)
Set-AdminPowerShellContextMenu.ps1
Kod: Tümünü seç
# =========================================================
# Script Name : Set-AdminPowerShellContextMenu.ps1
# Purpose : - Auto-detects the .ps1 ProgID and default "Run with PowerShell" verb
# - Adds "Run with PowerShell (Admin)" entry that opens an
# elevated PowerShell tab INSIDE Windows Terminal, launched
# via shell:AppsFolder\<AUMID> + runas (the supported way to
# elevate a packaged/MSIX app -- direct .exe paths under
# Program Files\WindowsApps are blocked by ACL for
# unpackaged callers).
# - Hides the default entry behind SHIFT (Extended)
# Usage : .\Set-AdminPowerShellContextMenu.ps1 -> Install
# .\Set-AdminPowerShellContextMenu.ps1 -Remove -> Uninstall / Restore
# =========================================================
param(
[switch]$Remove
)
# --- Require Administrator ---
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "This script must be run as Administrator." -ForegroundColor Red
Read-Host "Press ENTER to exit."
exit
}
$backupDir = "$env:USERPROFILE\Desktop"
$helperDir = "$env:ProgramData\ContextMenuTools"
$helperScriptPath = "$helperDir\Invoke-AdminPS1InTerminal.ps1"
$adminBasePath = "Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell\RunWithPowerShellAdmin"
$adminCommandPath = "$adminBasePath\command"
function Convert-ToRegExePath {
param([string]$PSPathValue)
return ($PSPathValue -replace '^.*Registry::', '')
}
function Get-Ps1ProgId {
$ext = Get-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\.ps1" -ErrorAction SilentlyContinue
if ($ext -and $ext."(default)") { return $ext."(default)" }
return $null
}
function Find-DefaultPowerShellVerb {
param([string]$ProgId)
$candidatePaths = @(
"Registry::HKEY_CLASSES_ROOT\$ProgId\Shell",
"Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell"
)
foreach ($shellRoot in $candidatePaths) {
if (-not (Test-Path $shellRoot)) { continue }
$verbs = Get-ChildItem -Path $shellRoot -ErrorAction SilentlyContinue
foreach ($verb in $verbs) {
$verbProps = Get-ItemProperty -Path $verb.PSPath -ErrorAction SilentlyContinue
$cmdKey = Join-Path $verb.PSPath "command"
if (-not (Test-Path $cmdKey)) { continue }
$cmdProps = Get-ItemProperty -Path $cmdKey -ErrorAction SilentlyContinue
$cmdValue = $cmdProps."(default)"
if (-not $cmdValue) { continue }
$hasShield = $verbProps.HasLUAShield
$isPwsh7 = $cmdValue -match "pwsh\.exe"
$isPlainPS = $cmdValue -match "\\powershell\.exe"
if ($isPwsh7) { continue }
if ($hasShield) { continue }
if ($verb.PSChildName -eq "RunWithPowerShellAdmin") { continue }
if ($isPlainPS) {
return [PSCustomObject]@{
PSPath = $verb.PSPath
Name = $verb.PSChildName
Extended = $verbProps.Extended
CommandLine = $cmdValue
}
}
}
}
return $null
}
function Get-WindowsTerminalAumid {
$pkg = Get-AppxPackage -Name "Microsoft.WindowsTerminal*" -ErrorAction SilentlyContinue | Select-Object -First 1
if (-not $pkg) { return $null }
try {
$manifest = Get-AppxPackageManifest -Package $pkg.PackageFullName -ErrorAction Stop
$appId = $manifest.Package.Applications.Application.Id
if (-not $appId) { return $null }
return "$($pkg.PackageFamilyName)!$appId"
}
catch {
return $null
}
}
# ---------------------------------------------------------
# Remove / Restore mode
# ---------------------------------------------------------
if ($Remove) {
if (Test-Path $adminBasePath) {
Remove-Item -Path $adminBasePath -Recurse -Force
Write-Host "Removed: Run with PowerShell (Admin) entry." -ForegroundColor Green
} else {
Write-Host "Admin entry not found, nothing to remove." -ForegroundColor Yellow
}
if (Test-Path $helperScriptPath) {
Remove-Item -Path $helperScriptPath -Force
Write-Host "Removed helper script: $helperScriptPath" -ForegroundColor Green
}
if ((Test-Path $helperDir) -and ((Get-ChildItem $helperDir -ErrorAction SilentlyContinue).Count -eq 0)) {
Remove-Item -Path $helperDir -Force
}
$progId = Get-Ps1ProgId
if ($progId) {
$detected = Find-DefaultPowerShellVerb -ProgId $progId
if ($detected -and $null -ne $detected.Extended) {
Remove-ItemProperty -Path $detected.PSPath -Name "Extended" -Force -ErrorAction SilentlyContinue
Write-Host "Restored visibility for: $($detected.Name)" -ForegroundColor Green
}
}
Read-Host "Press ENTER to exit."
exit
}
# ---------------------------------------------------------
# Install mode
# ---------------------------------------------------------
Write-Host "Detecting .ps1 file association..." -ForegroundColor Cyan
$progId = Get-Ps1ProgId
if (-not $progId) {
Write-Host "ERROR: Could not resolve ProgID for .ps1 files. Aborting." -ForegroundColor Red
Read-Host "Press ENTER to exit."
exit
}
Write-Host "Detected ProgID: $progId" -ForegroundColor Cyan
$detected = Find-DefaultPowerShellVerb -ProgId $progId
if ($detected) {
Write-Host "Detected entry to hide: $($detected.Name)" -ForegroundColor Green
} else {
Write-Host "WARNING: Could not auto-detect the default entry. It will not be hidden." -ForegroundColor Red
}
Write-Host "Detecting Windows Terminal AUMID..." -ForegroundColor Cyan
$aumid = Get-WindowsTerminalAumid
if (-not $aumid) {
Write-Host "ERROR: Could not resolve Windows Terminal's AUMID. Is it installed?" -ForegroundColor Red
Read-Host "Press ENTER to exit."
exit
}
Write-Host "Detected AUMID: $aumid" -ForegroundColor Green
# --- Create the helper script ---
# Direct .exe paths under Program Files\WindowsApps are blocked by ACL for
# unpackaged (regular desktop) callers. Packaged apps must instead be
# activated via shell:AppsFolder\<AUMID>, which IS supported for elevation
# via Start-Process -Verb RunAs. We bake the AUMID in at install time.
#
# NOTE: Uses a LITERAL here-string (@' '@) instead of an expandable one
# (@" "@) so that backticks and $ signs are written to the file exactly
# as typed, with no risk of double-escaping bugs. The AUMID is injected
# afterward via a plain, non-regex string replace.
if (-not (Test-Path $helperDir)) {
New-Item -Path $helperDir -ItemType Directory -Force | Out-Null
}
$helperTemplate = @'
param(
[Parameter(Mandatory = $true)]
[string]$TargetScript
)
$logFile = "$env:TEMP\AdminPS1InTerminal_lastrun.log"
"Run started: $(Get-Date)" | Out-File $logFile -Force
"TargetScript: $TargetScript" | Out-File $logFile -Append
if (-not (Test-Path -LiteralPath $TargetScript)) {
"ERROR: Target script not found." | Out-File $logFile -Append
Start-Process powershell.exe -ArgumentList "-NoExit -NoProfile -Command Write-Host 'Target script not found: $TargetScript' -ForegroundColor Red"
exit
}
$aumid = "__AUMID_PLACEHOLDER__"
$innerArgs = "powershell.exe -NoExit -NoProfile -ExecutionPolicy Bypass -File `"$TargetScript`""
try {
"Launching shell:AppsFolder\$aumid with args: $innerArgs" | Out-File $logFile -Append
Start-Process -FilePath "shell:AppsFolder\$aumid" -ArgumentList $innerArgs -Verb RunAs -ErrorAction Stop
"Launch issued successfully." | Out-File $logFile -Append
}
catch {
$errMsg = $_.Exception.Message
"ERROR: $errMsg" | Out-File $logFile -Append
Start-Process -FilePath "powershell.exe" -ArgumentList "-NoExit -NoProfile -Command Write-Host 'Elevation failed: $errMsg' -ForegroundColor Red"
}
'@
$helperContent = $helperTemplate.Replace('__AUMID_PLACEHOLDER__', $aumid)
Set-Content -Path $helperScriptPath -Value $helperContent -Encoding UTF8 -Force
Write-Host "Helper script created: $helperScriptPath" -ForegroundColor Green
# --- Add / update the always-visible admin entry ---
if (Test-Path $adminBasePath) {
$existingRegPath = Convert-ToRegExePath -PSPathValue (Get-Item $adminBasePath).PSPath
reg export "$existingRegPath" "$backupDir\ps1_shell_RunWithPowerShellAdmin_backup.reg" /y | Out-Null
Write-Host "Existing admin entry backed up." -ForegroundColor Yellow
}
New-Item -Path $adminCommandPath -Force | Out-Null
# The outer process is only a launcher that triggers elevation via the
# helper script; it has no other job, so it runs hidden and exits as soon
# as the helper script hands off to the elevated window. No -NoExit here.
$cmdValue = "powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File `"$helperScriptPath`" -TargetScript `"%1`""
Set-ItemProperty -Path $adminCommandPath -Name "(Default)" -Value $cmdValue
Write-Host "Added: Run with PowerShell (Admin) -> opens elevated PS tab in Windows Terminal via shell:AppsFolder." -ForegroundColor Green
# --- Hide the detected default entry behind SHIFT ---
if ($detected) {
$regPathForBackup = Convert-ToRegExePath -PSPathValue $detected.PSPath
$safeName = ($detected.Name -replace '[\\\/:]', '_')
reg export "$regPathForBackup" "$backupDir\ps1_shell_$safeName`_backup.reg" /y | Out-Null
Set-ItemProperty -Path $detected.PSPath -Name "Extended" -Value ""
Write-Host "Default '$($detected.Name)' is now hidden unless SHIFT is held during right-click." -ForegroundColor Green
}
Write-Host ""
Write-Host "Done. Right-click a .ps1 file and choose 'Run with PowerShell (Admin)'." -ForegroundColor Cyan
Write-Host "A single UAC prompt should appear, then Windows Terminal opens with an elevated PowerShell tab." -ForegroundColor Cyan
Read-Host "Press ENTER to exit."Sağ Menüye Ekleme :
Kod: Tümünü seç
.\Set-AdminPowerShellContextMenu.ps1 -> InstallKod: Tümünü seç
.\Set-AdminPowerShellContextMenu.ps1 -Remove -> Uninstall / RestoreEkran görüntüsü :

Güle güle kullanın her iki betiği de...(not: kararlı sürüm gelmeden betiği (birinci betiği) kullanmayın)














