diff --git a/scripts/update-all.cmd b/scripts/update-all.cmd index 31293b3..c980cce 100644 --- a/scripts/update-all.cmd +++ b/scripts/update-all.cmd @@ -209,8 +209,6 @@ try { Write-Host "" # Download en installeer updates - Show-Progress -Activity "Windows Updates" -Status "Download en installeer updates..." -PercentComplete 40 - $updatesToDownload = New-Object -ComObject Microsoft.Update.UpdateColl foreach ($update in $searchResult.Updates) { if ($update.IsDownloaded -eq $false) { @@ -220,17 +218,53 @@ try { if ($updatesToDownload.Count -gt 0) { Write-Host "Download $($updatesToDownload.Count) updates..." -ForegroundColor Cyan - $downloader = $updateSession.CreateUpdateDownloader() - $downloader.Updates = $updatesToDownload - $downloadResult = $downloader.Download() + Write-Host "" - if ($downloadResult.ResultCode -eq 2) { - Write-Host "✓ Updates succesvol gedownload" -ForegroundColor Green + # Download updates één voor één met voortgangsbalk + $downloadedCount = 0 + $successCount = 0 + foreach ($update in $updatesToDownload) { + $downloadedCount++ + $kbNumber = if ($update.KBArticleIDs.Count -gt 0) { "KB" + $update.KBArticleIDs.Item(0) } else { "Update" } + $updateTitle = if ($update.Title.Length -gt 60) { $update.Title.Substring(0, 57) + "..." } else { $update.Title } + $percentComplete = [math]::Round(((($downloadedCount - 1) / $updatesToDownload.Count) * 100)) + + Show-Progress -Activity "Windows Updates Downloaden" -Status "[$downloadedCount/$($updatesToDownload.Count)] $kbNumber - $updateTitle" -PercentComplete $percentComplete + Write-Host "[$downloadedCount/$($updatesToDownload.Count)] Download: $kbNumber" -ForegroundColor Cyan + + # Maak een nieuwe downloader voor deze update + $singleUpdateDownloader = $updateSession.CreateUpdateDownloader() + $singleUpdateColl = New-Object -ComObject Microsoft.Update.UpdateColl + $singleUpdateColl.Add($update) | Out-Null + $singleUpdateDownloader.Updates = $singleUpdateColl + + $singleDownloadResult = $singleUpdateDownloader.Download() + + # Update voortgangsbalk na download + $percentComplete = [math]::Round(($downloadedCount / $updatesToDownload.Count) * 100) + Show-Progress -Activity "Windows Updates Downloaden" -Status "[$downloadedCount/$($updatesToDownload.Count)] $kbNumber - Voltooid" -PercentComplete $percentComplete + + if ($singleDownloadResult.ResultCode -eq 2) { + Write-Host " ✓ Succesvol gedownload" -ForegroundColor Green + $successCount++ + } else { + Write-Host " ⚠ Gedeeltelijk gedownload (Code: $($singleDownloadResult.ResultCode))" -ForegroundColor Yellow + } + Write-Host "" + } + + Write-Progress -Activity "Windows Updates Downloaden" -Status "Voltooid!" -PercentComplete 100 + Start-Sleep -Milliseconds 500 + Write-Progress -Activity "Windows Updates Downloaden" -Completed + + if ($successCount -eq $updatesToDownload.Count) { + Write-Host "✓ Alle $successCount updates succesvol gedownload" -ForegroundColor Green Write-Log "Windows updates gedownload" "INFO" } else { - Write-Host "⚠ Download gedeeltelijk voltooid" -ForegroundColor Yellow + Write-Host "⚠ $successCount van $($updatesToDownload.Count) updates gedownload" -ForegroundColor Yellow Write-Log "Windows updates gedeeltelijk gedownload" "WARNING" } + Write-Host "" } # Installeer updates @@ -243,17 +277,56 @@ try { if ($updatesToInstall.Count -gt 0) { Write-Host "Installeer $($updatesToInstall.Count) updates..." -ForegroundColor Cyan - $installer = $updateSession.CreateUpdateInstaller() - $installer.Updates = $updatesToInstall - $installResult = $installer.Install() + Write-Host "" - if ($installResult.ResultCode -eq 2) { - Write-Host "✓ Windows updates succesvol geïnstalleerd" -ForegroundColor Green + # Installeer updates één voor één met voortgangsbalk + $installedCount = 0 + $successCount = 0 + foreach ($update in $updatesToInstall) { + $installedCount++ + $kbNumber = if ($update.KBArticleIDs.Count -gt 0) { "KB" + $update.KBArticleIDs.Item(0) } else { "Update" } + $updateTitle = if ($update.Title.Length -gt 60) { $update.Title.Substring(0, 57) + "..." } else { $update.Title } + $percentComplete = [math]::Round(((($installedCount - 1) / $updatesToInstall.Count) * 100)) + + Show-Progress -Activity "Windows Updates Installeren" -Status "[$installedCount/$($updatesToInstall.Count)] $kbNumber - $updateTitle" -PercentComplete $percentComplete + Write-Host "[$installedCount/$($updatesToInstall.Count)] Installeer: $kbNumber" -ForegroundColor Cyan + + # Maak een nieuwe installer voor deze update + $singleUpdateInstaller = $updateSession.CreateUpdateInstaller() + $singleInstallColl = New-Object -ComObject Microsoft.Update.UpdateColl + $singleInstallColl.Add($update) | Out-Null + $singleUpdateInstaller.Updates = $singleInstallColl + + $singleInstallResult = $singleUpdateInstaller.Install() + + # Update voortgangsbalk na installatie + $percentComplete = [math]::Round(($installedCount / $updatesToInstall.Count) * 100) + Show-Progress -Activity "Windows Updates Installeren" -Status "[$installedCount/$($updatesToInstall.Count)] $kbNumber - Voltooid" -PercentComplete $percentComplete + + if ($singleInstallResult.ResultCode -eq 2) { + Write-Host " ✓ Succesvol geïnstalleerd" -ForegroundColor Green + $successCount++ + } elseif ($singleInstallResult.ResultCode -eq 3) { + Write-Host " ℹ Herstart vereist (Code: $($singleInstallResult.ResultCode))" -ForegroundColor Yellow + $successCount++ + } else { + Write-Host " ⚠ Gedeeltelijk geïnstalleerd (Code: $($singleInstallResult.ResultCode))" -ForegroundColor Yellow + } + Write-Host "" + } + + Write-Progress -Activity "Windows Updates Installeren" -Status "Voltooid!" -PercentComplete 100 + Start-Sleep -Milliseconds 500 + Write-Progress -Activity "Windows Updates Installeren" -Completed + + if ($successCount -eq $updatesToInstall.Count) { + Write-Host "✓ Alle $successCount updates succesvol geïnstalleerd" -ForegroundColor Green Write-Log "Windows updates geïnstalleerd" "INFO" } else { - Write-Host "⚠ Installatie gedeeltelijk voltooid" -ForegroundColor Yellow + Write-Host "⚠ $successCount van $($updatesToInstall.Count) updates geïnstalleerd" -ForegroundColor Yellow Write-Log "Windows updates gedeeltelijk geïnstalleerd" "WARNING" } + Write-Host "" } } else { Write-Host "✓ Geen Windows updates beschikbaar" -ForegroundColor Green