Update some check-*.ps1 scripts

This commit is contained in:
Markus Fleschutz 2022-10-09 12:34:06 +02:00
parent b6baa94e3b
commit 888e0a5408
9 changed files with 50 additions and 60 deletions

View File

@ -22,17 +22,17 @@ try {
$Temp = [math]::round($Temp / 100.0, 1) $Temp = [math]::round($Temp / 100.0, 1)
} }
if ($Temp -gt 80) { if ($Temp -gt 80) {
$Reply = "CPU is $($Temp)°C extremely hot!" $Reply = "⚠️ CPU has $($Temp)°C - too hot!"
} elseif ($Temp -gt 50) { } elseif ($Temp -gt 50) {
$Reply = "CPU is $($Temp)°C hot." $Reply = "✅ CPU has $($Temp)°C - hot."
} elseif ($Temp -gt 0) { } elseif ($Temp -gt 0) {
$Reply = "CPU is $($Temp)°C warm." $Reply = "✅ CPU has $($Temp)°C - warm."
} elseif ($Temp -gt -20) { } elseif ($Temp -gt -20) {
$Reply = "CPU is $($Temp)°C cold." $Reply = "✅ CPU has $($Temp)°C - cold."
} else { } else {
$Reply = "CPU is $($Temp)°C extremely cold!" $Reply = "⚠️ CPU has $($Temp)°C - too cold!"
} }
& "$PSScriptRoot/give-reply.ps1" $Reply "$Reply"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -12,11 +12,11 @@
#> #>
try { try {
"⏳ Step 1/2 - Reading from Data/frequent-domains.csv..." Write-Progress "⏳ Step 1/2 - Reading from Data/frequent-domains.csv..."
$Table = Import-CSV "$PSScriptRoot/../Data/frequent-domains.csv" $Table = Import-CSV "$PSScriptRoot/../Data/frequent-domains.csv"
$NumRows = $Table.Length $NumRows = $Table.Length
"⏳ Step 2/2 - Resolving $NumRows domains..." Write-Progress "⏳ Step 2/2 - Resolving $NumRows domains..."
$StopWatch = [system.diagnostics.stopwatch]::startNew() $StopWatch = [system.diagnostics.stopwatch]::startNew()
if ($IsLinux) { if ($IsLinux) {
foreach($Row in $Table) { $null = dig $Row.Domain +short } foreach($Row in $Table) { $null = dig $Row.Domain +short }
@ -27,12 +27,15 @@ try {
[float]$Elapsed = $StopWatch.Elapsed.TotalSeconds [float]$Elapsed = $StopWatch.Elapsed.TotalSeconds
$Average = [math]::round($NumRows / $Elapsed, 1) $Average = [math]::round($NumRows / $Elapsed, 1)
if ($Average -gt 200.0) { $Rating = "excellent" } if ($Average -gt 200.0) {
elseif ($Average -gt 100.0) { $Rating = "quite good" } "$Average DNS domain lookups per second - excellent"
elseif ($Average -gt 10.0) { $Rating = "good" } } elseif ($Average -gt 100.0) {
else { $Rating = "poor" } "$Average DNS domain lookups per second - quite good"
} elseif ($Average -gt 10.0) {
"✔️ $Average DNS domain lookups per second - $Rating" "$Average DNS domain lookups per second - good"
} else {
"⚠️ $Average DNS domain lookups per second - poor"
}
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -11,6 +11,8 @@
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([int]$MinLevel = 50) # 50 GB minimum
try { try {
$Drives = Get-PSDrive -PSProvider FileSystem $Drives = Get-PSDrive -PSProvider FileSystem
foreach($Drive in $Drives) { foreach($Drive in $Drives) {
@ -20,13 +22,13 @@ try {
[int]$Total = ($Used + $Free) [int]$Total = ($Used + $Free)
if ($Total -eq "0") { if ($Total -eq "0") {
$Reply = "Drive $($Drive.Name) is empty." $Reply = "Drive $($Drive.Name) is empty."
} elseif ($Free -lt $MinLevel) { } elseif ($Free -lt $MinLevel) {
$Reply = "Drive $($Drive.Name) has only $Free GB left to use! $Used of $Total GB is in use." $Reply = "⚠️ Drive $($Drive.Name) has only $Free GB left to use! $Used of $Total GB is in use."
} else { } else {
$Reply = "Drive $($Drive.Name) has $($Free) GB left, $($Total) GB total." $Reply = "Drive $($Drive.Name) has $($Free) GB left, $($Total) GB total."
} }
"* $Reply" "$Reply"
} }
exit 0 # success exit 0 # success
} catch { } catch {

View File

@ -2,14 +2,9 @@
.SYNOPSIS .SYNOPSIS
Checks the computer health Checks the computer health
.DESCRIPTION .DESCRIPTION
This PowerShell script checks the health of the local computer. This PowerShell script checks some health parameter of the local computer.
.EXAMPLE .EXAMPLE
PS> ./check-health PS> ./check-health
1213 GB left for swap space (67 of 1280 GB used)
172 GB left on drive C (61 of 233 GB used)
30.3 °C CPU temperature - good
DNS resolution is 19.7 domains per second
29 ms ping average (13 ms min, 110 ms max, 10 hosts)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -27,4 +22,5 @@
if ($IsLinux) { if ($IsLinux) {
& "$PSScriptRoot/check-smart-devices.ps1" & "$PSScriptRoot/check-smart-devices.ps1"
} }
& "$PSScriptRoot/check-pending-reboot.ps1"
exit 0 # success exit 0 # success

View File

@ -21,7 +21,7 @@ try {
$OSversion = $OS.Version $OSversion = $OS.Version
$Reply = "$OSname for $OSarchitecture version $OSversion" $Reply = "$OSname for $OSarchitecture version $OSversion"
} }
& "$PSScriptRoot/give-reply.ps1" "$Reply" "$Reply"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -20,52 +20,44 @@ function Test-RegistryValue { param([parameter(Mandatory=$true)][ValidateNotNull
} }
} }
[bool]$PendingReboot = $false $Reason = ""
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired") { if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired") {
"Yes, found registry key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired'." $Reason +="found registry key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired'."
$PendingReboot = $true
} }
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting") { if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting") {
"Yes, found registry key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting'." $Reason += "found registry key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting'."
$PendingReboot = $true
} }
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending") { if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending") {
"Yes, found registry key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending'." $Reason += "found registry key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending'."
$PendingReboot = $true
} }
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts") { if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts") {
"Yes, found registry key 'HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts'." $Reason += "found registry key 'HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts'."
$PendingReboot = $true
} }
if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "RebootInProgress") { if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "RebootInProgress") {
"Yes, registry key 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing' contains 'RebootInProgress'." $Reason += "registry key 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing' contains 'RebootInProgress'."
$PendingReboot = $true
} }
if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "PackagesPending") { if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "PackagesPending") {
"Yes, registry key 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing' contains 'PackagesPending'." $Reason += "registry key 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing' contains 'PackagesPending'."
$PendingReboot = $true
} }
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations") { if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations") {
"Yes, registry key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' contains 'PendingFileRenameOperations'." $Reason += "registry key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' contains 'PendingFileRenameOperations'."
$PendingReboot = $true
} }
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations2") { if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations2") {
"Yes, registry key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' contains 'PendingFileRenameOperations2'." $Reason += "registry key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' contains 'PendingFileRenameOperations2'."
$PendingReboot = $true
} }
if (Test-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" -Value "DVDRebootSignal") { if (Test-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" -Value "DVDRebootSignal") {
"Yes, registry key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce' contains 'DVDRebootSignal'." $Reason += "registry key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce' contains 'DVDRebootSignal'."
$PendingReboot = $true
} }
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "JoinDomain") { if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "JoinDomain") {
"Yes, registry key 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon' contains 'JoinDomain'." $Reason += "registry key 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon' contains 'JoinDomain'."
$PendingReboot = $true
} }
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "AvoidSpnSet") { if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "AvoidSpnSet") {
"Yes, registry key 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon' contains 'AvoidSpnSet'." $Reason += "registry key 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon' contains 'AvoidSpnSet'."
$PendingReboot = $true }
if ($Reason -eq "") {
"✅ No pending reboot."
} else {
"pending reboot ($Reason)."
} }
if ($PendingReboot -eq $false) { "No pending reboot" }
exit 0 # success exit 0 # success

View File

@ -8,7 +8,7 @@
Specifies the hosts to check (separated by comma) Specifies the hosts to check (separated by comma)
.EXAMPLE .EXAMPLE
PS> ./check-ping PS> ./check-ping
Average ping is 36ms average (13ms min, 109ms max) Average ping is 36ms (13ms min, 109ms max)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -36,8 +36,7 @@ try {
$Avg += $Latency $Avg += $Latency
} }
$Avg = $Avg / $Pings.count $Avg = $Avg / $Pings.count
"✅ Average ping is $($Avg)ms ($($Min)ms min, $($Max)ms max)."
& "$PSScriptRoot/give-reply.ps1" "$($Avg)ms average ping time ($($Min)ms min, $($Max)ms max)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -7,7 +7,7 @@
Specifies the minimum level (50 GB by default) Specifies the minimum level (50 GB by default)
.EXAMPLE .EXAMPLE
PS> ./check-swap-space PS> ./check-swap-space
1213 GB left for swap space (67 of 1280 GB used) Swap space has 1826 GB left (1856 GB total)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -36,9 +36,9 @@ try {
} elseif ($Free -lt $MinLevel) { } elseif ($Free -lt $MinLevel) {
$Reply = "Swap space has only $Free GB left to use! ($Used of $Total GB used, minimum is $MinLevel GB)" $Reply = "Swap space has only $Free GB left to use! ($Used of $Total GB used, minimum is $MinLevel GB)"
} else { } else {
$Reply = "Swap space has $Free GB left ($Total GB total)" $Reply = "✅ Swap space has $Free GB left, $Total GB total."
} }
& "$PSScriptRoot/give-reply.ps1" "$Reply" "$Reply"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -19,12 +19,11 @@ try {
$TimeNow = Get-Date $TimeNow = Get-Date
$Uptime = New-TimeSpan -Start $BootTime.TimeCreated.Date -End $TimeNow $Uptime = New-TimeSpan -Start $BootTime.TimeCreated.Date -End $TimeNow
} }
$Days = $Uptime.Days $Days = $Uptime.Days
$Hours = $Uptime.Hours $Hours = $Uptime.Hours
$Minutes = $Uptime.Minutes $Minutes = $Uptime.Minutes
$Reply = "I'm up for " $Reply = "Up for "
if ($Days -eq "1") { if ($Days -eq "1") {
$Reply += "1 day, " $Reply += "1 day, "
} elseif ($Days -ne "0") { } elseif ($Days -ne "0") {
@ -40,8 +39,7 @@ try {
} elseif ($Minutes -ne "0") { } elseif ($Minutes -ne "0") {
$Reply += "and $Minutes minutes" $Reply += "and $Minutes minutes"
} }
$Reply += "." "$Reply."
& "$PSScriptRoot/give-reply.ps1" "$Reply"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"