From 6345a6cbc67957142529cf24bace0ec382d1ce5b Mon Sep 17 00:00:00 2001 From: Leonardo Klein Date: Wed, 18 Feb 2026 19:18:21 -0300 Subject: [PATCH] fix: correct Recheck stage SQL check and remove unused Timeout param - Recheck stage now respects $SkipSQLServiceCheck parameter instead of hardcoding $false - Remove unused $Timeout param from Invoke-UpdateCheck remote scriptblock and its ArgumentList since it was never used - Add null guard for $logFilePath in outer catch block - Fix author field to match repository convention Closes #4 Closes #5 --- .../System/Invoke-WindowsUpdateMaintenance.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Scripts/System/Invoke-WindowsUpdateMaintenance.ps1 b/Scripts/System/Invoke-WindowsUpdateMaintenance.ps1 index 64da665..727f85e 100644 --- a/Scripts/System/Invoke-WindowsUpdateMaintenance.ps1 +++ b/Scripts/System/Invoke-WindowsUpdateMaintenance.ps1 @@ -37,7 +37,7 @@ .NOTES File Name : Invoke-WindowsUpdateMaintenance.ps1 - Author : IT Operations Team + Author : Leonardo Klein Rezende Prerequisite : Administrator privileges, PowerShell 5.1+, PSWindowsUpdate module Creation Date : 2025-10-03 @@ -188,18 +188,16 @@ function Invoke-UpdateCheck { } $updates = Invoke-Command -ComputerName $server -ScriptBlock { - param($Timeout) - Import-Module PSWindowsUpdate -ErrorAction Stop - + $updateList = Get-WindowsUpdate -MicrosoftUpdate -AcceptAll -IgnoreReboot -Verbose:$false - + return @{ UpdateCount = $updateList.Count Updates = $updateList | Select-Object Title, Size, Description RequiresReboot = $updateList | Where-Object {$_.RebootRequired -eq $true} } - } -ArgumentList $TimeoutMinutes -ErrorAction Stop + } -ErrorAction Stop $results[$server] = @{ Status = "Success" @@ -465,7 +463,7 @@ try { "Recheck" { Write-MaintenanceLog "Starting recheck phase" -Level "INFO" -LogFilePath $logFilePath - $results = Invoke-UpdateCheck -ServerNames $connectivity.Available -LogFilePath $logFilePath -TimeoutMinutes $WSUSTimeoutMinutes -SkipSQLCheck $false + $results = Invoke-UpdateCheck -ServerNames $connectivity.Available -LogFilePath $logFilePath -TimeoutMinutes $WSUSTimeoutMinutes -SkipSQLCheck $SkipSQLServiceCheck.IsPresent } "Finalize" { @@ -481,7 +479,9 @@ try { } catch { $errorMessage = "Critical error during $Stage stage: $($_.Exception.Message)" - Write-MaintenanceLog $errorMessage -Level "ERROR" -LogFilePath $logFilePath + if ($logFilePath) { + Write-MaintenanceLog $errorMessage -Level "ERROR" -LogFilePath $logFilePath + } Write-Error $errorMessage exit 1 }