voorgang in update-all
This commit is contained in:
1 parent
a18e53adf9
commit
6b34e06863
1 file changed
+87
-14
+87
-14
@@ -209,8 +209,6 @@ try {
|
|||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
# Download en installeer updates
|
# Download en installeer updates
|
||||||
Show-Progress -Activity "Windows Updates" -Status "Download en installeer updates..." -PercentComplete 40
|
|
||||||
|
|
||||||
$updatesToDownload = New-Object -ComObject Microsoft.Update.UpdateColl
|
$updatesToDownload = New-Object -ComObject Microsoft.Update.UpdateColl
|
||||||
foreach ($update in $searchResult.Updates) {
|
foreach ($update in $searchResult.Updates) {
|
||||||
if ($update.IsDownloaded -eq $false) {
|
if ($update.IsDownloaded -eq $false) {
|
||||||
@@ -220,17 +218,53 @@ try {
|
|||||||
|
|
||||||
if ($updatesToDownload.Count -gt 0) {
|
if ($updatesToDownload.Count -gt 0) {
|
||||||
Write-Host "Download $($updatesToDownload.Count) updates..." -ForegroundColor Cyan
|
Write-Host "Download $($updatesToDownload.Count) updates..." -ForegroundColor Cyan
|
||||||
$downloader = $updateSession.CreateUpdateDownloader()
|
Write-Host ""
|
||||||
$downloader.Updates = $updatesToDownload
|
|
||||||
$downloadResult = $downloader.Download()
|
|
||||||
|
|
||||||
if ($downloadResult.ResultCode -eq 2) {
|
# Download updates één voor één met voortgangsbalk
|
||||||
Write-Host "✓ Updates succesvol gedownload" -ForegroundColor Green
|
$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"
|
Write-Log "Windows updates gedownload" "INFO"
|
||||||
} else {
|
} 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-Log "Windows updates gedeeltelijk gedownload" "WARNING"
|
||||||
}
|
}
|
||||||
|
Write-Host ""
|
||||||
}
|
}
|
||||||
|
|
||||||
# Installeer updates
|
# Installeer updates
|
||||||
@@ -243,17 +277,56 @@ try {
|
|||||||
|
|
||||||
if ($updatesToInstall.Count -gt 0) {
|
if ($updatesToInstall.Count -gt 0) {
|
||||||
Write-Host "Installeer $($updatesToInstall.Count) updates..." -ForegroundColor Cyan
|
Write-Host "Installeer $($updatesToInstall.Count) updates..." -ForegroundColor Cyan
|
||||||
$installer = $updateSession.CreateUpdateInstaller()
|
Write-Host ""
|
||||||
$installer.Updates = $updatesToInstall
|
|
||||||
$installResult = $installer.Install()
|
|
||||||
|
|
||||||
if ($installResult.ResultCode -eq 2) {
|
# Installeer updates één voor één met voortgangsbalk
|
||||||
Write-Host "✓ Windows updates succesvol geïnstalleerd" -ForegroundColor Green
|
$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"
|
Write-Log "Windows updates geïnstalleerd" "INFO"
|
||||||
} else {
|
} 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-Log "Windows updates gedeeltelijk geïnstalleerd" "WARNING"
|
||||||
}
|
}
|
||||||
|
Write-Host ""
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Write-Host "✓ Geen Windows updates beschikbaar" -ForegroundColor Green
|
Write-Host "✓ Geen Windows updates beschikbaar" -ForegroundColor Green
|
||||||
|
|||||||
Reference in new issue
Block a user