Windows Server 2025 Template Preparation Script
- RDP should be enabled manually before running
- VirtIO drivers should be installed before running
- Run Sysprep command separately via noVNC console
#Requires -RunAsAdministrator
$ErrorActionPreference = "Continue"
Write-Host "Starting Windows Server 2025 Template Preparation..." -ForegroundColor Green
# ============================================================
# 1. REMOTE DESKTOP (Manual - Already Done)
# ============================================================
# Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0
# Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
Write-Host "[1/10] Remote Desktop: Skipped (enable manually)" -ForegroundColor Yellow
# ============================================================
# 2. FIREWALL - PING (ICMP)
# ============================================================
Write-Host "[2/10] Configuring Firewall - ICMP..." -ForegroundColor Cyan
netsh advfirewall firewall set rule name="File and Printer Sharing (Echo Request - ICMPv4-In)" new enable=yes profile=any
# ============================================================
# ============================================================
Write-Host "[3/10] Setting Timezone..." -ForegroundColor Cyan
Set-TimeZone -Id "W. Europe Standard Time"
# ============================================================
# 4. LANGUAGE & REGIONAL SETTINGS
# ============================================================
Write-Host "[4/10] Configuring Language Settings..." -ForegroundColor Cyan
Set-WinUILanguageOverride en-US
Set-WinSystemLocale -SystemLocale en-US
Set-WinUserLanguageList de-CH -Force
$1 = Get-WinUserLanguageList
$1.RemoveAll( { $args[0].LanguageTag -clike '' } )
Set-WinUserLanguageList $1 -Force
# ============================================================
# ============================================================
Write-Host "[5/10] Configuring Power Settings..." -ForegroundColor Cyan
powercfg /change monitor-timeout-ac 0
# ============================================================
# 6. SYSPREP COUNTER RESET
# ============================================================
Write-Host "[6/10] Resetting Sysprep Counter..." -ForegroundColor Cyan
Set-ItemProperty -Path "HKLM:\SYSTEM\Setup\Status\SysprepStatus" -Name "CleanupState" -Value 2
Set-ItemProperty -Path "HKLM:\SYSTEM\Setup\Status\SysprepStatus" -Name "GeneralizationState" -Value 7
# ============================================================
# 7. CLEANUP - TEMP FILES
# ============================================================
Write-Host "[7/10] Cleaning Temp Files..." -ForegroundColor Cyan
Remove-Item -Path "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "C:\Windows\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
# ============================================================
# 8. CLEANUP - EVENT LOGS
# ============================================================
Write-Host "[8/10] Clearing Event Logs..." -ForegroundColor Cyan
# ============================================================
# 9. WINDOWS UPDATE CLEANUP (Optional)
# ============================================================
Write-Host "[9/10] Windows Update Cleanup..." -ForegroundColor Cyan
# Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
Write-Host "[10/10] Preparation Complete!" -ForegroundColor Green
Write-Host "NEXT STEPS:" -ForegroundColor Yellow
Write-Host "1. Open noVNC Console (NOT RDP!)" -ForegroundColor Yellow
Write-Host "2. Run the Sysprep command below" -ForegroundColor Yellow