Private/Clear-WUUpgradeBlockingRegistry.ps1

function Clear-WUUpgradeBlockingRegistry {
    <#
    .SYNOPSIS
        Clears registry entries that may block Windows Update upgrades.
 
    .DESCRIPTION
        Removes compatibility markers and upgrade experience indicators from the registry
        that may prevent Windows feature updates from installing successfully.
 
    .PARAMETER LogPath
        Path to the log file for detailed logging.
 
    .EXAMPLE
        $result = Clear-WUUpgradeBlockingRegistry -LogPath "C:\Logs\wu.log"
 
    .NOTES
        This is a private function used internally by the WindowsUpdateTools module.
        Returns an object with Success, EntriesCleared, and ActionsPerformed properties.
    #>


    [CmdletBinding()]
    param(
        [string]$LogPath
    )
    
    $result = [PSCustomObject]@{
        Success = $false
        EntriesCleared = 0
        ActionsPerformed = @()
    }
    
    try {
        Write-WULog -Message "Clearing upgrade-blocking registry entries..." -LogPath $LogPath
        
        $regPaths = @(
            "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\CompatMarkers",
            "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\UpgradeExperienceIndicators"
        )
        
        foreach ($regPath in $regPaths) {
            if (Test-Path $regPath) {
                Remove-Item -Path $regPath -Recurse -Force -ErrorAction SilentlyContinue
                Write-WULog -Message "Cleared registry path: $regPath" -LogPath $LogPath
                $result.EntriesCleared++
            }
        }
        
        $result.ActionsPerformed += "Registry cleanup completed"
        $result.Success = $true
    }
    catch {
        Write-WULog -Message "Error during registry cleanup: $($_.Exception.Message)" -Level Warning -LogPath $LogPath
    }
    
    return $result
}