From 83438af6df5c80f80c265886d05090c669b957c4 Mon Sep 17 00:00:00 2001 From: Kevin Simmons Date: Sun, 4 Oct 2026 14:14:47 -0500 Subject: [PATCH] Fix critical and medium issues in HealthCheck script --- HealthCheck/PCHealthCheck.ps1 | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/HealthCheck/PCHealthCheck.ps1 b/HealthCheck/PCHealthCheck.ps1 index a7852d0..d723d9d 100644 --- a/HealthCheck/PCHealthCheck.ps1 +++ b/HealthCheck/PCHealthCheck.ps1 @@ -108,6 +108,7 @@ PC Health Check - Remote Edition ================================================================================ #> # Command-line parameters +[CmdletBinding(SupportsShouldProcess=$true)] param ( [Parameter(Mandatory=$false)] [string[]]$ComputerName, @@ -1114,9 +1115,10 @@ function Get-ServicesStatus { } $color = "Green" - if ($service.Status -ne "Running") { $color = "Red" } + $statusLevel = "Good" + if ($service.Status -ne "Running") { $color = "Red"; $statusLevel = "Warning" } - Write-ColorOutput "$($service.DisplayName): $($service.Status)" $color $ComputerName + Write-ColorOutput "$($service.DisplayName): $($service.Status)" $color $statusLevel $ComputerName } catch { Write-ColorOutput "Error checking service $serviceName on $ComputerName" "Red" $ComputerName @@ -1387,11 +1389,6 @@ function Run-AllChecks { $reportPath = Save-HtmlReport -ComputerName $ComputerName if (-not $Silent) { Write-Host "`nHTML report generated: $reportPath" -ForegroundColor Green - Write-Host "Would you like to open the report now? (Y/N)" -ForegroundColor Yellow - $openReport = Read-Host - if ($openReport -like "Y*") { - Start-Process $reportPath - } } } } @@ -1455,7 +1452,7 @@ function Check-PendingReboot { if ($regProv) { # Check CBS RebootPending $csbValue = $regProv.GetStringValue(2147483650, "$regKey\RebootPending", "") - if ($csbValue.sValue -eq "1") { + if ($csbValue -and $csbValue.sValue -eq "1") { $rebootPending = $true $rebootReasons += "Component Based Servicing (CBS)" } @@ -1463,7 +1460,7 @@ function Check-PendingReboot { # Check Windows Update RebootRequired $wuKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" $wuValue = $regProv.GetStringValue(2147483650, "$wuKey\RebootRequired", "") - if ($wuValue.sValue -eq "1") { + if ($wuValue -and $wuValue.sValue -eq "1") { $rebootPending = $true $rebootReasons += "Windows Update" } @@ -1526,7 +1523,7 @@ function Check-NetworkAdapters { Write-ColorOutput "`nActive Network Adapters:" "White" $ComputerName foreach ($adapter in $adapters) { - if ($adapter.NetConnectionStatus -eq 2 -or $adapter.NetConnectionStatus -eq 7) { + if ($adapter.NetConnectionStatus -eq 2) { $status = "Connected" $statusColor = "Green" } else { @@ -1636,9 +1633,10 @@ while (-not $exitRequested) { "L" { Show-LogFiles } "E" { # Generate and open HTML report + $originalExportHTML = $ExportHTML $ExportHTML = $true Run-AllChecks - $ExportHTML = $false + $ExportHTML = $originalExportHTML } "Q" { Write-ColorOutput "Exiting script..." "Cyan"