Function WriteLastLines () {
param (
[array] $InputArray
)
$lineCount = 0
[array]::Reverse($InputArray)
ForEach ($line In $InputArray) {
If ($line.StartsWith("[")) {Break}
$lineCount++
}
[array]::Reverse($InputArray)
For ($i=($InputArray.GetUpperBound("") - $lineCount);$i -le ($InputArray.GetUpperBound(""));$i++) {
Write-Host $InputArray[$i]
}
}
$clean = "The component store has been corrupted."
$restore = "The restore operation completed successfully."
while ($clean.Contains("The component store has been corrupted.") -And $restore.Contains("The restore operation completed successfully.")) {
$counter++
Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") | $counter | Restore"
$restore = @(dism /online /cleanup-image /restorehealth /Source:E:\winsxs /LimitAccess)
WriteLastLines $restore
Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") | $counter | Clean"
$clean = @(dism /online /cleanup-image /startcomponentcleanup)
WriteLastLines -InputArray $clean
PAUSE
}