@@ -8,8 +8,10 @@ $ScriptVersion = 'nextgen-0.1-DB6'
88param (
99 [switch ]$all ,
1010 [string []]$modules ,
11+ [string []]$exclude ,
1112 [switch ]$interactive ,
12- [switch ]$dryrun
13+ [switch ]$dryrun ,
14+ [switch ]$whatif
1315)
1416
1517# --- Version Banner ---
@@ -26,15 +28,43 @@ Write-Host "Script started at: $(Get-Date)" -ForegroundColor Yellow
2628Write-Host " Running from: $PSScriptRoot " - ForegroundColor Yellow
2729Write-Host " ================================`n "
2830
31+ # Registry backup/export before changes
32+ function Export-RegistryBackup {
33+ $backupDir = Join-Path $PSScriptRoot " registry-backups"
34+ if (-not (Test-Path $backupDir )) { New-Item - ItemType Directory - Path $backupDir | Out-Null }
35+ $timestamp = Get-Date - Format ' yyyyMMdd_HHmmss'
36+ $backupFile = Join-Path $backupDir " regbackup_$timestamp .reg"
37+ Write-Host " Exporting registry backup to $backupFile ..." - ForegroundColor Cyan
38+ reg export HKLM $backupFile / y | Out-Null
39+ Write-Host " ✓ Registry backup complete." - ForegroundColor Green
40+ }
41+
42+ # Only export backup if not dryrun
43+ if (-not $dryrun ) { Export-RegistryBackup }
44+
45+
2946# Logging setup
3047$logFile = Join-Path $PSScriptRoot " telemetry-blocker.log"
3148function Write-Log {
32- param ([string ]$msg )
49+ param ([string ]$msg , [ switch ] $Error )
3350 $timestamp = Get-Date - Format " yyyy-MM-dd HH:mm:ss"
34- " $timestamp $msg " | Out-File - FilePath $logFile - Append - Encoding utf8
51+ $entry = " $timestamp $msg "
52+ $entry | Out-File - FilePath $logFile - Append - Encoding utf8
53+ if ($Error ) {
54+ $errorLogFile = Join-Path $PSScriptRoot " telemetry-blocker-errors.log"
55+ $entry | Out-File - FilePath $errorLogFile - Append - Encoding utf8
56+ }
3557}
3658
59+ # Log Windows version and build number at the start
60+ $osInfo = Get-CimInstance - ClassName Win32_OperatingSystem
61+ $winVersion = $osInfo.Version
62+ $winBuild = $osInfo.BuildNumber
3763Write-Log " === Script started ==="
64+ Write-Log " Windows Version: $winVersion "
65+ Write-Log " Windows Build: $winBuild "
66+ Write-Log " Script Version: $ScriptVersion "
67+ $reportFile = Join-Path $PSScriptRoot " telemetry-blocker-report.md"
3868
3969# Check if modules directory exists
4070$modulesDir = Join-Path $PSScriptRoot " modules"
@@ -378,6 +408,7 @@ foreach ($mod in $toRunResolved) {
378408 }
379409}
380410
411+
381412$endTime = Get-Date
382413$duration = $endTime - $startTime
383414Write-Stats " Execution started: $startTime "
@@ -408,5 +439,44 @@ Write-Host "Error log: $errorLogFile" -ForegroundColor Yellow
408439if ($rollbackModules.Count -gt 0 ) {
409440 Write-Host " Rollback modules executed: $ ( $rollbackModules -join ' , ' ) " - ForegroundColor Red
410441}
442+
443+ # --- Generate Markdown/HTML Report ---
444+ $reportContent = @ ()
445+ $reportContent += " # Windows Telemetry Blocker - Change Report"
446+ $reportContent += " "
447+ $reportContent += " **Date:** $ ( Get-Date ) "
448+ $reportContent += " **Script Version:** $ScriptVersion "
449+ $reportContent += " **Windows Version:** $winVersion "
450+ $reportContent += " **Windows Build:** $winBuild "
451+ $reportContent += " **Execution Time:** $ ( $duration.ToString ()) "
452+ $reportContent += " "
453+ $reportContent += " ## Modules Run"
454+ $moduleKeys = $moduleResults.Keys
455+ foreach ($mod in $moduleKeys ) {
456+ $res = $moduleResults [$mod ]
457+ $line = " - $mod $ ( $res.Status ) (Start: $ ( $res.Start ) , End: $ ( $res.End ) )"
458+ if ($res.Error ) { $line += " - Error: $ ( $res.Error ) " }
459+ $reportContent += $line
460+ }
461+ $reportContent += " "
462+ $reportContent += " ## Summary"
463+ foreach ($item in $summary ) {
464+ $reportContent += " - $item "
465+ }
466+ $reportContent += " "
467+ if ($rollbackModules.Count -gt 0 ) {
468+ $reportContent += " ## Rollback Modules"
469+ $reportContent += " - $ ( $rollbackModules -join ' , ' ) "
470+ }
471+ $reportContent += " "
472+ $errors = Get-Content - Path $errorLogFile - ErrorAction SilentlyContinue
473+ if ($errors -and $errors.Count -gt 0 ) {
474+ $reportContent += " ## Errors"
475+ foreach ($err in $errors ) { $reportContent += " - $err " }
476+ }
477+
478+ $reportContent | Set-Content - Path $reportFile - Encoding utf8
479+
480+ Write-Host " Report written to: $reportFile " - ForegroundColor Green
411481Write-Host " Press any key to exit..."
412482$null = $Host.UI.RawUI.ReadKey (" NoEcho,IncludeKeyDown" )
0 commit comments