Compare commits

...

3 Commits

Author SHA1 Message Date
27a97e4650 Update functions/public/Invoke-WPFUpdateMGMGT.ps1
Co-authored-by: Mr.k <mineshtine28546271@gmail.com>
2025-03-07 18:21:14 +01:00
dc236b9865 Update functions/public/Invoke-WPFUpdateMGMGT.ps1
Co-authored-by: CodingWonders <101426328+CodingWonders@users.noreply.github.com>
2025-03-07 18:16:06 +01:00
f9878a3472 Disable the 'Scan for Updates' Button when the task is running (#13)
Co-authored-by: MyDrift <personal@mdiana.ch>
2025-03-07 18:06:35 +01:00
2 changed files with 25 additions and 6 deletions

View File

@ -4,6 +4,11 @@ function Invoke-WPFUpdateMGMT {
[switch]$All [switch]$All
) )
if ((-not $Selected -and -not $All) -or ($Selected -and $All)) {
Write-Host "[Invoke-WPFUpdateMGMT] Use either 'Selected' or 'All' switches, used switches are: 'Selected' is $Selected, 'All' is $All" -ForegroundColor Red
return
}
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" }) $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
if ($All) { if ($All) {
@ -33,10 +38,18 @@ function Invoke-WPFUpdateMGMT {
param ($selectedUpdates, $WPFUpdateVerbose) param ($selectedUpdates, $WPFUpdateVerbose)
foreach ($update in $selectedUpdates) { foreach ($update in $selectedUpdates) {
Write-Host "Installing update $($update.Title) on $($update.ComputerName)" Write-Host "Installing update $($update.Title) on $($update.ComputerName)"
if ($WPFUpdateVerbose) { if ($update.KB -ne "") {
Get-WindowsUpdate -ComputerName $update.ComputerName -Title $update.Title -Install -Confirm:$false -Verbose -IgnoreReboot:$true -IgnoreRebootRequired:$true if ($WPFUpdateVerbose) {
Get-WindowsUpdate -ComputerName $update.ComputerName -KBArticleID $update.KB -Install -Confirm:$false -Verbose -IgnoreReboot:$true -IgnoreRebootRequired:$true
} else {
Get-WindowsUpdate -ComputerName $update.ComputerName -KBArticleID $update.KB -Install -Confirm:$false -IgnoreReboot:$true -IgnoreRebootRequired:$true
}
} else { } else {
Get-WindowsUpdate -ComputerName $update.ComputerName -Title $update.Title -Install -Confirm:$false -IgnoreReboot:$true -IgnoreRebootRequired:$true if ($WPFUpdateVerbose) {
Get-WindowsUpdate -ComputerName $update.ComputerName -Title "$($update.Title)" -Install -Confirm:$false -Verbose -IgnoreReboot:$true -IgnoreRebootRequired:$true
} else {
Get-WindowsUpdate -ComputerName $update.ComputerName -Title "$($update.Title)" -Install -Confirm:$false -IgnoreReboot:$true -IgnoreRebootRequired:$true
}
} }
} }
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" }) $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })

View File

@ -1,8 +1,9 @@
function Invoke-WPFUpdatesScan { function Invoke-WPFUpdatesScan {
$sync["WPFScanUpdates"].IsEnabled = $false
$sync["WPFUpdateSelectedInstall"].IsEnabled = $false
$sync["WPFUpdateAllInstall"].IsEnabled = $false
Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo"
Invoke-WPFRunspace -DebugPreference $DebugPreference -ScriptBlock { Invoke-WPFRunspace -DebugPreference $DebugPreference -ScriptBlock {
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
# Check if the PSWindowsUpdate module is installed # Check if the PSWindowsUpdate module is installed
if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) { if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
try { try {
@ -12,6 +13,7 @@ function Invoke-WPFUpdatesScan {
} }
catch { catch {
Write-Error "Failed to install PSWindowsUpdate module: $_" Write-Error "Failed to install PSWindowsUpdate module: $_"
$sync.form.Dispatcher.Invoke([action] { $sync["WPFScanUpdates"].IsEnabled = $true })
return return
} }
} }
@ -23,6 +25,7 @@ function Invoke-WPFUpdatesScan {
} }
catch { catch {
Write-Error "Failed to import PSWindowsUpdate module: $_" Write-Error "Failed to import PSWindowsUpdate module: $_"
$sync.form.Dispatcher.Invoke([action] { $sync["WPFScanUpdates"].IsEnabled = $true })
return return
} }
@ -58,4 +61,7 @@ function Invoke-WPFUpdatesScan {
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -overlay "warning" }) $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -overlay "warning" })
} }
} }
$sync["WPFScanUpdates"].IsEnabled = $false
$sync["WPFUpdateSelectedInstall"].IsEnabled = $false
$sync["WPFUpdateAllInstall"].IsEnabled = $false
} }