mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-11-26 07:26:18 +01:00
fix(registry-restore): continue restoring remaining keys when one fails (#837)
Co-authored-by: Jeffrey <9938813+Raphire@users.noreply.github.com>
This commit is contained in:
co-authored by
Jeffrey
parent
e6184a2597
commit
f39885f6f2
@@ -246,9 +246,29 @@ function Restore-RegistryBackupState {
|
||||
$restoreAction = {
|
||||
param($normalizedBackup)
|
||||
|
||||
Write-Host "Applying registry restore from $(@($normalizedBackup.RegistryKeys).Count) root snapshot(s)."
|
||||
foreach ($rootSnapshot in @($normalizedBackup.RegistryKeys)) {
|
||||
Restore-RegistryKeySnapshot -Snapshot $rootSnapshot
|
||||
$rootSnapshots = @($normalizedBackup.RegistryKeys)
|
||||
|
||||
foreach ($rootSnapshot in $rootSnapshots) {
|
||||
Test-RegistryKeySnapshotCanBeRestored -Snapshot $rootSnapshot
|
||||
}
|
||||
|
||||
Write-Host "Applying registry restore from $($rootSnapshots.Count) root snapshot(s)."
|
||||
$failureCount = 0
|
||||
|
||||
foreach ($rootSnapshot in $rootSnapshots) {
|
||||
try {
|
||||
Restore-RegistryKeySnapshot -Snapshot $rootSnapshot
|
||||
}
|
||||
catch {
|
||||
$failureCount++
|
||||
Write-Warning "Failed to restore '$($rootSnapshot.Path)': $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
if ($failureCount -gt 0) {
|
||||
$restoreError = [System.InvalidOperationException]::new("Registry restore finished with $failureCount failed key(s). See console for details.")
|
||||
$restoreError.Data['RegistryRestoreFailureCount'] = $failureCount
|
||||
throw $restoreError
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user