mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-07-01 18:42:35 -05:00
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
This commit is contained in:
@ -61,6 +61,10 @@ function Invoke-WPFButton {
|
||||
"WPFWinUtilInstallPSProfile" {Invoke-WinUtilInstallPSProfile}
|
||||
"WPFWinUtilUninstallPSProfile" {Invoke-WinUtilUninstallPSProfile}
|
||||
"WPFWinUtilSSHServer" {Invoke-WPFSSHServer}
|
||||
"WPFScanUpdates" {Invoke-WPFScanUpdates}
|
||||
"WPFScanUpdates" {Invoke-WPFUpdatesScan}
|
||||
"WPFShowUpdateHistory" { Invoke-WPFUpdateHistoryToggle }
|
||||
"WPFUpdateSelectedInstall" {Invoke-WPFUpdateMGMT -Selected}
|
||||
"WPFUpdateAllInstall" {Invoke-WPFUpdateMGMT -All}
|
||||
"WPFUpdateScanHistory" {Invoke-WPFUpdateScanHistory}
|
||||
}
|
||||
}
|
||||
|
11
functions/public/Invoke-WPFUpdateHistoryToggle.ps1
Normal file
11
functions/public/Invoke-WPFUpdateHistoryToggle.ps1
Normal file
@ -0,0 +1,11 @@
|
||||
function Invoke-WPFUpdateHistoryToggle {
|
||||
if ($sync["WPFShowUpdateHistory"].Content -eq "Show History") {
|
||||
$sync["WPFShowUpdateHistory"].Content = "Show available Updates"
|
||||
$sync["HistoryGrid"].Visibility = "Visible"
|
||||
$sync["UpdatesGrid"].Visibility = "Collapsed"
|
||||
} else {
|
||||
$sync["WPFShowUpdateHistory"].Content = "Show History"
|
||||
$sync["HistoryGrid"].Visibility = "Collapsed"
|
||||
$sync["UpdatesGrid"].Visibility = "Visible"
|
||||
}
|
||||
}
|
13
functions/public/Invoke-WPFUpdateMGMGT.ps1
Normal file
13
functions/public/Invoke-WPFUpdateMGMGT.ps1
Normal file
@ -0,0 +1,13 @@
|
||||
function Invoke-WPFUpdateMGMT {
|
||||
param (
|
||||
[switch]$Selected,
|
||||
[switch]$All
|
||||
)
|
||||
|
||||
if ($Selected) {
|
||||
write-host "Installing selected updates"
|
||||
} elseif ($All) {
|
||||
Write-Host "Installing all available updates"
|
||||
}
|
||||
|
||||
}
|
46
functions/public/Invoke-WPFUpdateScanHistory.ps1
Normal file
46
functions/public/Invoke-WPFUpdateScanHistory.ps1
Normal file
@ -0,0 +1,46 @@
|
||||
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."
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
function Invoke-WPFScanUpdates {
|
||||
function Invoke-WPFUpdatesScan {
|
||||
|
||||
|
||||
Invoke-WPFRunspace -DebugPreference $DebugPreference -ScriptBlock {
|
||||
@ -26,7 +26,6 @@ function Invoke-WPFScanUpdates {
|
||||
}
|
||||
|
||||
try {
|
||||
Write-Host "Clearing updates list..."
|
||||
$sync.form.Dispatcher.Invoke([action] { $sync["WPFUpdatesList"].Items.Clear() })
|
||||
Write-Host "Scanning for Windows updates..."
|
||||
$updates = Get-WindowsUpdate -ErrorAction Stop
|
||||
@ -35,13 +34,21 @@ function Invoke-WPFScanUpdates {
|
||||
$sync.form.Dispatcher.Invoke([action] {
|
||||
foreach ($update in $updates) {
|
||||
$item = New-Object PSObject -Property @{
|
||||
ComputerName = $update.ComputerName
|
||||
KB = $update.KB
|
||||
Size = $update.Size
|
||||
Title = $update.Title -replace '\s*\(KB\d+\)', '' -replace '\s*KB\d+\b', '' # Remove KB number from title, first in parentheses, then standalone
|
||||
Status = "Not Installed"
|
||||
}
|
||||
$Computers = $item | Select-Object -ExpandProperty ComputerName -Unique
|
||||
$sync["WPFUpdatesList"].Items.Add($item)
|
||||
}
|
||||
if ($Computers.Count -gt 1) {
|
||||
$sync["WPFUpdatesList"].Columns[0].Visibility = "Visible"
|
||||
} else {
|
||||
Write-Debug "Hiding ComputerName column, only $item.ComputerName"
|
||||
$sync["WPFUpdatesList"].Columns[0].Visibility = "Collapsed"
|
||||
}
|
||||
})
|
||||
} catch {
|
||||
Write-Error "Error scanning for updates: $_"
|
Reference in New Issue
Block a user