Files
PowerShell-scripts/SCCM-WU/SCCM-WU-Diag.ps1
T
2026-07-08 14:17:23 +02:00

172 lines
7.0 KiB
PowerShell

$ErrorActionPreference = 'SilentlyContinue'
$outDir = 'C:\install'
if (-not (Test-Path $outDir)) {
New-Item -Path $outDir -ItemType Directory -Force | Out-Null
}
$outFile = Join-Path $outDir 'WU-Diag.txt'
if (Test-Path $outFile) {
Remove-Item $outFile -Force
}
function Log {
param([string]$Text)
Add-Content -Path $outFile -Value $Text
}
function Section {
param([string]$Title)
Log ''
Log ('=' * 70)
Log "== $Title"
Log ('=' * 70)
Write-Host "Bezig: $Title"
}
Log "WU/SCCM Diagnose - $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
Log "Server: $env:COMPUTERNAME"
# -------------------------------------------------------------
Section '1. OS informatie'
$os = Get-CimInstance Win32_OperatingSystem
Log "Caption: $($os.Caption)"
Log "Build: $($os.BuildNumber)"
Log "Version: $($os.Version)"
Log "LastBoot: $($os.LastBootUpTime)"
# -------------------------------------------------------------
Section '2. Laatste 10 hotfixes'
Get-HotFix | Sort-Object InstalledOn -Descending |
Select-Object -First 10 HotFixID, Description, InstalledOn |
Format-Table -AutoSize | Out-String | ForEach-Object { Log $_ }
# -------------------------------------------------------------
Section '3. Pending reboot status'
$cbsPending = Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending'
$wuPending = Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired'
$fileRename = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager').PendingFileRenameOperations
Log "CBS RebootPending: $cbsPending"
Log "WU RebootRequired: $wuPending"
Log "PendingFileRenameOperations: $([bool]$fileRename)"
# -------------------------------------------------------------
Section '4. WindowsUpdate policy registry (volledig)'
$wu = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate'
if (Test-Path $wu) {
Get-ItemProperty $wu | Select-Object * -ExcludeProperty PS* |
Format-List | Out-String | ForEach-Object { Log $_ }
} else {
Log 'Key bestaat niet'
}
# -------------------------------------------------------------
Section '5. WindowsUpdate\AU policy registry (volledig)'
$au = "$wu\AU"
if (Test-Path $au) {
Get-ItemProperty $au | Select-Object * -ExcludeProperty PS* |
Format-List | Out-String | ForEach-Object { Log $_ }
} else {
Log 'Key bestaat niet'
}
# -------------------------------------------------------------
Section '6. UX Settings (lokale WU config)'
$ux = 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings'
if (Test-Path $ux) {
Get-ItemProperty $ux | Select-Object * -ExcludeProperty PS* |
Format-List | Out-String | ForEach-Object { Log $_ }
} else {
Log 'Key bestaat niet'
}
# -------------------------------------------------------------
Section '7. WUA Service Manager (welke update sources kent WUA)'
$sm = New-Object -ComObject Microsoft.Update.ServiceManager
foreach ($s in $sm.Services) {
Log "Name: $($s.Name) | Default: $($s.IsDefaultAUService) | Managed: $($s.IsManaged) | ServiceID: $($s.ServiceID)"
}
# -------------------------------------------------------------
Section '8. WUA versie'
$wuaDll = Get-Item "$env:SystemRoot\System32\wuaueng.dll"
Log "wuaueng.dll versie: $($wuaDll.VersionInfo.ProductVersion)"
# -------------------------------------------------------------
Section '9. SCCM client info'
$ccm = Get-CimInstance -Namespace root\ccm -ClassName SMS_Client
Log "Client versie: $($ccm.ClientVersion)"
$site = Get-CimInstance -Namespace root\ccm -ClassName SMS_Authority
Log "Site: $($site.Name)"
Log "MP: $($site.CurrentManagementPoint)"
# -------------------------------------------------------------
Section '10. CCM UpdatesStore (alle updates + status)'
Get-WmiObject -Namespace root\ccm\SoftwareUpdates\UpdatesStore -Class CCM_UpdateStatus |
Select-Object Status, Article, Title, ScanTime |
Sort-Object Status |
Format-Table -AutoSize | Out-String -Width 300 | ForEach-Object { Log $_ }
# -------------------------------------------------------------
Section '11. CCM Update Assignments (deployments die de client kent)'
Get-WmiObject -Namespace root\ccm\Policy\Machine\ActualConfig -Class CCM_UpdateCIAssignment |
Select-Object AssignmentName, AssignmentID, EnforcementDeadline, StartTime, SuppressReboot |
Format-Table -AutoSize | Out-String -Width 300 | ForEach-Object { Log $_ }
# -------------------------------------------------------------
Section '12. Aantal update CIs per assignment'
$assignments = Get-WmiObject -Namespace root\ccm\Policy\Machine\ActualConfig -Class CCM_UpdateCIAssignment
foreach ($a in $assignments) {
$ciCount = ($a.AssignedCIs | Measure-Object).Count
Log "$($a.AssignmentName): $ciCount CIs"
}
# -------------------------------------------------------------
Section '13. Software Center - wat de client als beschikbaar ziet'
Get-CimInstance -Namespace root\ccm\ClientSDK -ClassName CCM_SoftwareUpdate |
Select-Object ArticleID, Name, ComplianceState, EvaluationState, Deadline |
Format-Table -AutoSize | Out-String -Width 300 | ForEach-Object { Log $_ }
$suCount = (Get-CimInstance -Namespace root\ccm\ClientSDK -ClassName CCM_SoftwareUpdate | Measure-Object).Count
Log "Totaal updates zichtbaar voor Software Center: $suCount"
# -------------------------------------------------------------
Section '14. WUAHandler.log (laatste 60 regels)'
Get-Content 'C:\Windows\CCM\Logs\WUAHandler.log' -Tail 60 | ForEach-Object { Log $_ }
# -------------------------------------------------------------
Section '15. ScanAgent.log (laatste 40 regels)'
Get-Content 'C:\Windows\CCM\Logs\ScanAgent.log' -Tail 40 | ForEach-Object { Log $_ }
# -------------------------------------------------------------
Section '16. UpdatesDeployment.log (laatste 60 regels)'
Get-Content 'C:\Windows\CCM\Logs\UpdatesDeployment.log' -Tail 60 | ForEach-Object { Log $_ }
# -------------------------------------------------------------
Section '17. UpdatesHandler.log (laatste 40 regels)'
Get-Content 'C:\Windows\CCM\Logs\UpdatesHandler.log' -Tail 40 | ForEach-Object { Log $_ }
# -------------------------------------------------------------
Section '18. WindowsUpdate.log genereren (laatste 100 regels)'
$wuLog = Join-Path $outDir 'WindowsUpdate.log'
Get-WindowsUpdateLog -LogPath $wuLog | Out-Null
if (Test-Path $wuLog) {
Get-Content $wuLog -Tail 100 | ForEach-Object { Log $_ }
} else {
Log 'WindowsUpdate.log genereren mislukt'
}
# -------------------------------------------------------------
Section '19. GPO herkomst (gpresult samenvatting)'
$gpFile = Join-Path $outDir 'gpresult.txt'
gpresult /scope computer /v > $gpFile 2>&1
Log "Volledige gpresult staat in: $gpFile"
$gpContent = Get-Content $gpFile
$wuLines = $gpContent | Select-String -Pattern 'WindowsUpdate|Defer|DualScan|WUServer|Update' -Context 2, 2
foreach ($line in $wuLines) {
Log $line.ToString()
}
Log ''
Log "Diagnose compleet: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
Write-Host ''
Write-Host "Klaar! Output staat in: $outFile"
Write-Host "Extra bestanden: $wuLog en $gpFile"