Skip to content

updated LKGC script v1.3 - #127

Open
anmocanu wants to merge 7 commits into
Azure:mainfrom
anmocanu:patch-10
Open

updated LKGC script v1.3#127
anmocanu wants to merge 7 commits into
Azure:mainfrom
anmocanu:patch-10

Conversation

@anmocanu

Copy link
Copy Markdown
Contributor

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

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
@EdwinBernal1
EdwinBernal1 self-requested a review June 16, 2026 13:58
@EdwinBernal1

EdwinBernal1 commented Jun 16, 2026

Copy link
Copy Markdown
Member

Issues Found

🟢 Minor: OS version parsing is heuristic-based

The script derives $winosver from first numeric token in ProductName. This is pragmatic but brittle if naming format changes.

Recommendation: consider reading a stable version key (e.g., CurrentMajorVersionNumber / CurrentBuild) when available.

anmocanu added 3 commits July 13, 2026 16:58
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.
@EdwinBernal1

Copy link
Copy Markdown
Member

@anmocanu could you help us with the review of these findings

Findings

Critical

File Context Issue Recommendation
None

Warning

File Context Issue Recommendation
win-LKGC.ps1 version number PR title says v1.3, but the top .VERSION entry in the file is v1.4 ("Production hardening"). Reconcile the version in the title/history so it is unambiguous.
win-LKGC.ps1 Log-* wrapper Logging-wrapper pattern duplicated across the batch. Extract shared helper.

Info

File Context Suggestion
win-LKGC.ps1 backup + rollback SYSTEM hive backup with restore-on-failure is the strongest safety pattern in the batch. Good.
win-LKGC.ps1 AND-logic fix The OR→AND change is a genuine bug fix; verify the version-specific thresholds (Win10/2016+ vs 2012) match intended LKGC semantics.
win-LKGC.ps1 unload retry Pre-load defensive reg unload, plus 3× unload retry with GC — reduces stuck-hive risk on detach.

Operational Risk Assessment

Factor Rating Notes
Scope Low-Medium Single script; registry hive load/modify/unload.
Destructive ops Low-Medium Registry Select edits — but backed up and rolled back on failure.
Rollback possible Yes Per-disk SYSTEM hive backup + automatic restore on failure.
Testing documented Unknown Confirm test evidence in the PR.
Gen compatibility Gen1+Gen2 Operates on the lettered Windows volume; generation-agnostic.

anmocanu added 3 commits July 20, 2026 17:50
Refactored logging mechanism to use Log-* functions for better consistency and clarity. Updated comments and improved error handling for registry operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants