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 # Command-line parameters
[CmdletBinding(SupportsShouldProcess=$true)]
param ( param (
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[string[]]$ComputerName, [string[]]$ComputerName,
@@ -1114,9 +1115,10 @@ function Get-ServicesStatus {
} }
$color = "Green" $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 { catch {
Write-ColorOutput "Error checking service $serviceName on $ComputerName" "Red" $ComputerName Write-ColorOutput "Error checking service $serviceName on $ComputerName" "Red" $ComputerName
@@ -1387,11 +1389,6 @@ function Run-AllChecks {
$reportPath = Save-HtmlReport -ComputerName $ComputerName $reportPath = Save-HtmlReport -ComputerName $ComputerName
if (-not $Silent) { if (-not $Silent) {
Write-Host "`nHTML report generated: $reportPath" -ForegroundColor Green 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) { if ($regProv) {
# Check CBS RebootPending # Check CBS RebootPending
$csbValue = $regProv.GetStringValue(2147483650, "$regKey\RebootPending", "") $csbValue = $regProv.GetStringValue(2147483650, "$regKey\RebootPending", "")
if ($csbValue.sValue -eq "1") { if ($csbValue -and $csbValue.sValue -eq "1") {
$rebootPending = $true $rebootPending = $true
$rebootReasons += "Component Based Servicing (CBS)" $rebootReasons += "Component Based Servicing (CBS)"
} }
@@ -1463,7 +1460,7 @@ function Check-PendingReboot {
# Check Windows Update RebootRequired # Check Windows Update RebootRequired
$wuKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" $wuKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
$wuValue = $regProv.GetStringValue(2147483650, "$wuKey\RebootRequired", "") $wuValue = $regProv.GetStringValue(2147483650, "$wuKey\RebootRequired", "")
if ($wuValue.sValue -eq "1") { if ($wuValue -and $wuValue.sValue -eq "1") {
$rebootPending = $true $rebootPending = $true
$rebootReasons += "Windows Update" $rebootReasons += "Windows Update"
} }
@@ -1526,7 +1523,7 @@ function Check-NetworkAdapters {
Write-ColorOutput "`nActive Network Adapters:" "White" $ComputerName Write-ColorOutput "`nActive Network Adapters:" "White" $ComputerName
foreach ($adapter in $adapters) { foreach ($adapter in $adapters) {
if ($adapter.NetConnectionStatus -eq 2 -or $adapter.NetConnectionStatus -eq 7) { if ($adapter.NetConnectionStatus -eq 2) {
$status = "Connected" $status = "Connected"
$statusColor = "Green" $statusColor = "Green"
} else { } else {
@@ -1636,9 +1633,10 @@ while (-not $exitRequested) {
"L" { Show-LogFiles } "L" { Show-LogFiles }
"E" { "E" {
# Generate and open HTML report # Generate and open HTML report
$originalExportHTML = $ExportHTML
$ExportHTML = $true $ExportHTML = $true
Run-AllChecks Run-AllChecks
$ExportHTML = $false $ExportHTML = $originalExportHTML
} }
"Q" { "Q" {
Write-ColorOutput "Exiting script..." "Cyan" Write-ColorOutput "Exiting script..." "Cyan"