Fix critical and medium issues in HealthCheck script

This commit is contained in:
Kevin Simmons committed 2026-10-04 14:14:47 -05:00
1 parent 311499546a
commit 83438af6df
1 file changed
+9 -11
+9 -11
View File
@@ -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"