Auto-commit: 2025-10-31 08:55:43

This commit is contained in:
David Wuibaille
2025-10-31 08:55:43 +01:00
parent 9bb5ad24bb
commit 24c0c6509f
33 changed files with 13144 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
# Initializations
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
$computerScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$summariesComputerFailed = $wsus.GetSummariesPerComputerTarget($updateScope,$computerScope) | Where-Object FailedCount -NE 0 | Sort-Object FailedCount, UnknownCount, NotInstalledCount -Descending
$computers = Get-WsusComputer
$computersErrorEvents = $wsus.GetUpdateEventHistory([System.DateTime]::Today.AddDays(-7), [System.DateTime]::Today) | Where-Object ComputerId -ne [Guid]::Empty | Where-Object IsError -eq $true
function Get-TimeStamp {
return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
}
$csvFile = "$PSScriptRoot\WSUSFailedComputer_" + "{0:MMddyy}" -f (Get-Date) + ".csv"
Get-WsusComputer -ComputerUpdateStatus Failed | Export-Csv -Path $csvFile -NoTypeInformation
$ComputersErrorToday = Get-WsusComputer -ComputerUpdateStatus Failed
$csvList = (Get-ChildItem -Path $PSScriptRoot -Filter *.csv).FullName
$AllCsv = $csvList | Import-Csv
$AllCsv = $AllCsv | Sort-Object "FullDomainName"
$Ordinateur = @()
$CountError = 1
$OldComputer = "XXXX"
Foreach ($csv In $AllCsv) {
$FullDomainName = $csv.FullDomainName
$ExitError = $true
Foreach ($ComputerErrorToday In $ComputersErrorToday) {
$FullNameComputerErrorToday = $ComputerErrorToday.FullDomainName
if ($FullNameComputerErrorToday -eq $FullDomainName) { $ExitError = $false }
}
If (-not $ExitError) {
If ($OldComputer -eq $FullDomainName) {
$CountError += 1
} Else {
if ($OldComputer -ne "XXXX") {
$CountError = $CountError.ToString("0000")
$Ordinateur += "$CountError;$OldComputer"
}
$CountError = 1
$OldComputer = $FullDomainName
}
}
}
$Ordinateur = $Ordinateur | Sort-Object -Descending
$TotalAffiche = 10
$NbAffiche = 0
Foreach ($Computererror In $Ordinateur) {
If ($NbAffiche -lt $TotalAffiche) {
Write-Host $Computererror
$NbAffiche += 1
$NomOrdinateur = $Computererror.Substring(5)
ForEach ($computerFailed In $summariesComputerFailed) {
$computer = $computers | Where-Object Id -eq $computerFailed.ComputerTargetId
$Computername = $computer.FullDomainName
$ComputerIP = $computer.IPAddress
if ($Computername -eq $NomOrdinateur) {
$computerUpdatesFailed = ($wsus.GetComputerTargets($computerScope) | Where-Object Id -EQ $computerFailed.ComputerTargetId).GetUpdateInstallationInfoPerUpdate($updateScope) | Where-Object UpdateInstallationState -EQ "Failed"
ForEach ($update In $computerUpdatesFailed) {
$outputText = $wsus.GetUpdate($update.UpdateId).Title
Write-Host "------------ $outputText"
}
}
}
}
}

View File

@@ -0,0 +1,27 @@
# WSUS Failed Computers (Display.ps1)
Generate a CSV of client machines that had Windows Update installation errors over a recent time window, by querying **WSUS event history (errors only)**. Faster and more accurate than stitching multiple daily exports. If the `UpdateServices` module isnt present, the script uses the WSUS Admin .NET DLL directly.
---
## Requirements
- Run on the **WSUS server**, in an **elevated** 64-bit Windows PowerShell (5.1).
- WSUS PowerShell module `UpdateServices` (installed with WSUS/RSAT) **or** the Admin DLL:
`C:\Program Files\Update Services\Tools\Microsoft.UpdateServices.Administration.dll`
- Local access to WSUS (HTTP 8530 or HTTPS 8531).
---
## Install
1. Copy the script here: `DisplayToErrorComputer/Display.ps1`
2. Unblock if downloaded from the internet:
```powershell
Unblock-File .\Display.ps1
```
## How to run
Standard run (last 7 days, top 100):
```powershell
.\Display.ps1 -Days 7 -Top 100 -Verbose
```