winutil/functions/public/Invoke-WPFUpdateScanHistory.ps1
MyDrift e830ff03b1 add Update History
- add Computername into DataGrid (if needed)
- add toggle for Update History
- add Update History interface
- add Update Interface Toggle Logic
- add Update scan logic
- initialize Update selected / all logic
- center specific datagrid columns
2025-03-04 20:46:06 +01:00

47 lines
2.3 KiB
PowerShell

function Invoke-WPFUpdateScanHistory {
$sync["WPFUpdateHistory"].Items.Clear()
Invoke-WPFRunspace -DebugPreference $DebugPreference -ScriptBlock {
write-host "Scanning for Windows update history..."
$UpdateHistory = Get-WUHistory -Last 50 -ErrorAction SilentlyContinue
if ($UpdateHistory) {
foreach ($update in $UpdateHistory) {
$item = New-Object PSObject -Property @{
ComputerName = $update.ComputerName
Result = $update.Result
Title = $update.Title -replace '\s*\(KB\d+\)', '' -replace '\s*KB\d+\b', '' # Remove KB number from title, first in parentheses, then standalone
KB = $update.KB
Date = $update.Date
}
$Computers = $item | Select-Object -ExpandProperty ComputerName -Unique
$sync.form.Dispatcher.Invoke([action] {
$sync["WPFUpdateHistory"].Items.Add($item)
if ($item.Result -eq "Succeeded") {
# does not work : $sync["WPFUpdateHistory"].Items[$sync["WPFUpdateHistory"].Items.Count - 1].Foreground = "Green"
#write-host "$($item.Title) was successful"
}
elseif ($item.Result -eq "Failed") {
# does not work : $sync["WPFUpdateHistory"].Items[$sync["WPFUpdateHistory"].Items.Count - 1].Foreground = "Red"
#write-host "$($item.Title) failed"
}
})
}
write-host "Found $($UpdateHistory.Count) updates."
$sync.form.Dispatcher.Invoke([action] {
if ($Computers.Count -gt 1) {
$sync["WPFUpdateHistory"].Columns[0].Visibility = "Visible"
}
else {
Write-Debug "Hiding ComputerName column, only $item.ComputerName"
$sync["WPFUpdateHistory"].Columns[0].Visibility = "Collapsed"
}
})
}
else {
$sync.form.Dispatcher.Invoke([action] {
$sync["WPFUpdateHistory"].Items.Clear()
})
Write-Host "No update history available."
}
}
}