From 4ada589b40fc39de655383aa79276b87af4a75c4 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 28 Dec 2022 17:49:03 +0100 Subject: [PATCH] Updated some check-*.ps1 scripts --- Scripts/cd-ssh.ps1 | 14 +++++++------- Scripts/check-cpu.ps1 | 16 +++++++++------- Scripts/check-dns.ps1 | 5 ++++- Scripts/check-gpu.ps1 | 2 +- Scripts/check-health.ps1 | 8 +++++--- Scripts/check-ping.ps1 | 7 +++++-- Scripts/check-ram.ps1 | 2 +- 7 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Scripts/cd-ssh.ps1 b/Scripts/cd-ssh.ps1 index 10a5049d..c7ff5b4c 100755 --- a/Scripts/cd-ssh.ps1 +++ b/Scripts/cd-ssh.ps1 @@ -13,14 +13,14 @@ #> try { - $Path = Resolve-Path "$HOME/.ssh" - if (-not(Test-Path "$Path" -pathType container)) { - throw "SSH folder at 📂$Path doesn't exist (yet)" + $Path = Resolve-Path "~/.ssh" + if (Test-Path "$Path" -pathType container) { + Set-Location "$Path" + "📂$Path" + exit 0 # success } - Set-Location "$Path" - "📂$Path" - exit 0 # success + throw "User's SSH folder at 📂$Path doesn't exist (yet)" } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 -} +} \ No newline at end of file diff --git a/Scripts/check-cpu.ps1 b/Scripts/check-cpu.ps1 index b117878b..0d309eed 100755 --- a/Scripts/check-cpu.ps1 +++ b/Scripts/check-cpu.ps1 @@ -55,17 +55,19 @@ try { $Arch = "" } if ([System.Environment]::Is64BitOperatingSystem) { $Bits = "64-bit" } else { $Bits = "32-bit" } - $Cores = [System.Environment]::ProcessorCount - "$Status $Arch CPU $Bits ($Cores cores, $Temp)" + $CPUName = "$Arch CPU $Bits" + $DeviceID = "" + $Speed = "" + $Socket = "" } else { $Details = Get-WmiObject -Class Win32_Processor $CPUName = $Details.Name.trim() - $Cores = [System.Environment]::ProcessorCount - $DeviceID = $Details.DeviceID - $Speed = "$($Details.MaxClockSpeed)MHz" - $Socket = $Details.SocketDesignation - "$Status $CPUName ($Cores cores, $DeviceID, $Speed, $Socket socket, $Temp)" + $DeviceID = "$($Details.DeviceID), " + $Speed = "$($Details.MaxClockSpeed)MHz, " + $Socket = "$($Details.SocketDesignation) socket, " } + $Cores = [System.Environment]::ProcessorCount + Write-Host "$Status $CPUName ($Cores cores, $($DeviceID)$($Speed)$($Socket)$Temp)" exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/check-dns.ps1 b/Scripts/check-dns.ps1 index 8fe49385..48360e88 100755 --- a/Scripts/check-dns.ps1 +++ b/Scripts/check-dns.ps1 @@ -25,8 +25,11 @@ try { } [float]$Elapsed = $StopWatch.Elapsed.TotalSeconds + Write-Progress -Completed " " $Average = [math]::round($NumRows / $Elapsed, 1) - if ($Average -gt 10.0) { + if ($Average -gt 100.0) { + "✅ DNS resolves excellent $Average domains per second" + } elseif ($Average -gt 10.0) { "✅ DNS resolves $Average domains per second" } else { "⚠️ DNS resolves only $Average domains per second!" diff --git a/Scripts/check-gpu.ps1 b/Scripts/check-gpu.ps1 index 85255994..3f7f2f5d 100644 --- a/Scripts/check-gpu.ps1 +++ b/Scripts/check-gpu.ps1 @@ -36,7 +36,7 @@ try { $RefreshRate = $Details.CurrentRefreshRate $DriverVersion = $Details.DriverVersion $Status = $Details.Status - "✅ $Model GPU ($(Bytes2String $RAMSize) RAM, $($ResWidth)x$($ResHeight) pixels, $BitsPerPixel bit, $RefreshRate Hz, driver $DriverVersion, status $Status)" + Write-Host "✅ $Model GPU ($(Bytes2String $RAMSize) RAM, $($ResWidth)x$($ResHeight) pixels, $BitsPerPixel bit, $RefreshRate Hz, driver $DriverVersion, status $Status)" } } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/check-health.ps1 b/Scripts/check-health.ps1 index 28e96d18..a040482e 100755 --- a/Scripts/check-health.ps1 +++ b/Scripts/check-health.ps1 @@ -31,8 +31,10 @@ & "$PSScriptRoot/check-uptime.ps1" & "$PSScriptRoot/check-time-zone.ps1" & "$PSScriptRoot/check-swap-space.ps1" -& "$PSScriptRoot/check-dns.ps1" -& "$PSScriptRoot/check-ping.ps1" -& "$PSScriptRoot/check-vpn.ps1" & "$PSScriptRoot/check-pending-reboot.ps1" +" " +& "$PSScriptRoot/write-green.ps1" " N E T W O R K" +& "$PSScriptRoot/check-ping.ps1" +& "$PSScriptRoot/check-dns.ps1" +& "$PSScriptRoot/check-vpn.ps1" exit 0 # success \ No newline at end of file diff --git a/Scripts/check-ping.ps1 b/Scripts/check-ping.ps1 index 3a01bc23..800aef82 100755 --- a/Scripts/check-ping.ps1 +++ b/Scripts/check-ping.ps1 @@ -7,7 +7,7 @@ Specifies the hosts to check, seperated by comma (default is: amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com) .EXAMPLE PS> ./check-ping - ✅ Ping is 25ms average, 13ms min, 109ms max. + ✅ Ping is 25ms average, 13ms min, 109ms max .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -17,10 +17,11 @@ param([string]$hosts = "amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com") try { - Write-Progress "⏳ Pinging $hosts..." + Write-Progress "⏳ (1/2) Pinging $hosts..." $HostsArray = $hosts.Split(",") $Pings = Test-Connection -count 1 -computerName $HostsArray + Write-Progress "⏳ (2/2) Calculating results..." [int]$Min = 9999999 [int]$Max = [int]$Avg = 0 foreach($Ping in $Pings) { @@ -30,6 +31,8 @@ try { $Avg += $Latency } $Avg /= $Pings.count + + Write-Progress -Completed " " "✅ Ping is $($Avg)ms average, $($Min)ms min, $($Max)ms max" exit 0 # success } catch { diff --git a/Scripts/check-ram.ps1 b/Scripts/check-ram.ps1 index f3a6fdcb..9e9c4bf2 100644 --- a/Scripts/check-ram.ps1 +++ b/Scripts/check-ram.ps1 @@ -69,7 +69,7 @@ try { [float]$Voltage = $Bank.ConfiguredVoltage / 1000.0 $Manufacturer = $Bank.Manufacturer $Location = "$($Bank.BankLabel)/$($Bank.DeviceLocator)" - "✅ $Capacity $Type ($($Speed)MHz, $($Voltage)V) at $Location by $Manufacturer" + Write-Host "✅ $Capacity $Type ($($Speed)MHz, $($Voltage)V) at $Location by $Manufacturer" } } exit 0 # success