updated LKGC script v1.3 - #127
Conversation
This script enables Last Known Good Configuration (LKGC) by incrementing registry values for recovery from boot issues. It includes enhancements for logging and error handling, ensuring proper execution and tracking of applied changes.
This update enhances the win-LKGC.ps1 script to increment Last Known Good Configuration (LKGC) registry values, log changes, and ensure proper handling of nested VMs. It includes improved error handling, logging, and a new mechanism to track whether LKGC was applied on any disk.
.VERSION
v1.3: [May 2026] - Updated the script (current)
- Added LKGC_APPLIED log flag (per disk + overall) and corrected final summary message.
- Fixed Get-VM crash when Hyper-V module is not installed on host (guarded Get-VM).
- Fixed false "already set" detection by requiring ALL thresholds (AND instead of OR).
v1.1: Previous version
v0.1: Initial commit
Issues Found🟢 Minor: OS version parsing is heuristic-basedThe script derives Recommendation: consider reading a stable version key (e.g., CurrentMajorVersionNumber / CurrentBuild) when available. |
This update includes a production hardening update with several enhancements such as path validation, logging improvements, and backup functionality. It also introduces summary counters for processed, skipped, failed, and changed operations.
|
Tony Mocanu (@anmocanu) could you help us with the review of these findings FindingsCritical
Warning
Info
Operational Risk Assessment
|
Refactored logging mechanism to use Log-* functions for better consistency and clarity. Updated comments and improved error handling for registry operations.
VMRepair Script Update: win-LKGC.ps1🎯 SummaryComprehensive testing and validation of win-LKGC.ps1 (v1.3) with fault injection verification across 6 VM configurations. ✅ Test ResultsOverall Score: 78.4/100 (Grade: B)
🔬 Testing PerformedStrategy: Representative (6 configurations) Test Configurations
Fault Injection Validation:
📊 Detailed Test ArtifactsComplete test artifacts available in SME work item:
🔗 SME Work Item: Tooling 59898 win-LKGC 🚀 Improvements Recommended1. ❌ Header Documentation (37/100) — BLOCKINGCurrent Issues:
Recommendation: Add both fields to the PowerShell comment block. 2. ❌ Telemetry Coverage (0%) — High PriorityCurrent Issues:
Recommendation: Add telemetry at minimum for script start, success (with # Example additions:
Log-Start -Message "Starting LKGC restoration" -Properties @{
OSVersion = $productName
SelectBefore = "$($before.Current),$($before.Default),$($before.Failed),$($before.LastKnownGood)"
}
# ... repair logic ...
Log-Output "LKGC APPLIED" -Properties @{
SelectAfter = "$($after.Current),$($after.Default),$($after.Failed),$($after.LastKnownGood)"
}3. ℹ️ Minor — Trailing Whitespace (PSScriptAnalyzer)Lines 6, 8, 10, 11 have trailing whitespace. Not blocking but clean to fix. Generated by VMRepairMint Script Testing Framework |
This script enables Last Known Good Configuration (LKGC) by incrementing registry values for recovery from boot issues. It includes enhancements for logging and error handling, ensuring proper execution and tracking of applied changes. This update enhances the win-LKGC.ps1 script to increment Last Known Good Configuration (LKGC) registry values, log changes, and ensure proper handling of nested VMs. It includes improved error handling, logging, and a new mechanism to track whether LKGC was applied on any disk. .VERSION
v1.3: [May 2026] - Updated the script (current)
- Added LKGC_APPLIED log flag (per disk + overall) and corrected final summary message.
- Fixed Get-VM crash when Hyper-V module is not installed on host (guarded Get-VM).
- Fixed false "already set" detection by requiring ALL thresholds (AND instead of OR).
v1.1: Previous version
v0.1: Initial commit