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 Validated — win-LKGC.ps1 v1.3Tested by: VMRepairMint Script Testing Framework Test Results — 6/6 VMs FIXED (100%)
Scores
Improvements Recommended1. ❌ Header Documentation (37/100)
2. ❌ Telemetry Coverage (0%)No Log-Start -Message "Starting LKGC restoration" -Properties @{
SelectBefore = "$($before.Current),$($before.Default),$($before.Failed),$($before.LastKnownGood)"
}
Log-Output "LKGC APPLIED" -Properties @{
SelectAfter = "$($after.Current),$($after.Default),$($after.Failed),$($after.LastKnownGood)"
}3. ℹ️ Minor — Trailing Whitespace (PSScriptAnalyzer)Lines 6, 8, 10, 11. Not blocking. 🔗 SME Work Item: Tooling 59898 win-LKGC |
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