From 0cef271a2981e54e7b326cd0b143da149d90fd9d Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Sun, 1 Jan 2023 19:22:35 +0100 Subject: [PATCH] Updated some check-*.ps1 scripts --- Scripts/check-apps.ps1 | 8 +-- Scripts/check-battery.ps1 | 2 +- Scripts/check-cpu.ps1 | 3 +- Scripts/check-dns.ps1 | 14 +++--- Scripts/check-drives.ps1 | 1 + Scripts/check-gpu.ps1 | 1 + Scripts/check-os.ps1 | 6 +-- Scripts/check-pending-reboot.ps1 | 84 +++++++++++++++++--------------- Scripts/check-ping.ps1 | 6 +-- Scripts/check-powershell.ps1 | 2 +- Scripts/check-smart-devices.ps1 | 11 +++-- Scripts/check-swap-space.ps1 | 12 ++--- Scripts/check-vpn.ps1 | 6 +-- 13 files changed, 82 insertions(+), 74 deletions(-) diff --git a/Scripts/check-apps.ps1 b/Scripts/check-apps.ps1 index 7b272ea5..3d191f21 100644 --- a/Scripts/check-apps.ps1 +++ b/Scripts/check-apps.ps1 @@ -15,7 +15,7 @@ try { if ($IsLinux) { # TODO } else { - Write-Progress "⏳ (1/2) Querying installed apps (for current user only)..." + Write-Progress "⏳ Querying installed apps..." $Apps = Get-AppxPackage [int]$NumInstalled = $Apps.Count [int]$NumIssues = 0 @@ -23,12 +23,12 @@ try { if ($App.Status -ne "Ok") { $NumIssues++ } } - Write-Progress "⏳ (2/2) Querying available updates..." + Write-Progress "⏳ Querying available updates..." $NumUpdates = (winget upgrade --include-unknown).Count - 5 - Write-Progress -Completed " " [int]$NumErrors = (Get-AppxLastError) - "✅ $NumInstalled apps installed, $NumIssues non-ok, $NumErrors errors, $NumUpdates updates available" + Write-Host "✅ $NumInstalled apps installed, $NumIssues non-ok, $NumErrors errors, $NumUpdates updates available" + Write-Progress -Completed " " } exit 0 # success } catch { diff --git a/Scripts/check-battery.ps1 b/Scripts/check-battery.ps1 index ba566603..4b576a73 100644 --- a/Scripts/check-battery.ps1 +++ b/Scripts/check-battery.ps1 @@ -30,7 +30,7 @@ try { if ($Remaining -lt 30) { $Status = "⚠️" } $Battery = "$Percent% battery life, $Remaining min. left" } - "$Status $Power, $Battery" + Write-Host "$Status $Power, $Battery" } exit 0 # success } catch { diff --git a/Scripts/check-cpu.ps1 b/Scripts/check-cpu.ps1 index 5e488825..9b0eeac0 100755 --- a/Scripts/check-cpu.ps1 +++ b/Scripts/check-cpu.ps1 @@ -30,7 +30,7 @@ function GetCPUTemperatureInCelsius { } try { - Write-Progress "Querying CPU details ..." + Write-Progress "⏳ Querying CPU details ..." $Status = "✅" $Celsius = GetCPUTemperatureInCelsius if ($Celsius -eq 99999.9) { @@ -68,6 +68,7 @@ try { } $Cores = [System.Environment]::ProcessorCount Write-Host "$Status $CPUName ($Cores cores, $($DeviceID)$($Speed)$($Socket)$Temp)" + Write-Progress -Completed " " exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/check-dns.ps1 b/Scripts/check-dns.ps1 index 48360e88..df5f7541 100755 --- a/Scripts/check-dns.ps1 +++ b/Scripts/check-dns.ps1 @@ -12,11 +12,11 @@ #> try { - Write-Progress "⏳ (1/2) Loading Data/popular-domains.csv..." + Write-Progress "⏳ Loading Data/popular-domains.csv..." $Table = Import-CSV "$PSScriptRoot/../Data/popular-domains.csv" $NumRows = $Table.Length - Write-Progress "⏳ (2/2) Resolving $NumRows domains..." + Write-Progress "⏳ Resolving $NumRows domains..." $StopWatch = [system.diagnostics.stopwatch]::startNew() if ($IsLinux) { foreach($Row in $Table){$nop=dig $Row.Domain +short} @@ -25,17 +25,17 @@ try { } [float]$Elapsed = $StopWatch.Elapsed.TotalSeconds - Write-Progress -Completed " " $Average = [math]::round($NumRows / $Elapsed, 1) if ($Average -gt 100.0) { - "✅ DNS resolves excellent $Average domains per second" + Write-Host "✅ DNS resolves excellent $Average domains per second" } elseif ($Average -gt 10.0) { - "✅ DNS resolves $Average domains per second" + Write-Host "✅ DNS resolves $Average domains per second" } else { - "⚠️ DNS resolves only $Average domains per second!" + Write-Host "⚠️ DNS resolves only $Average domains per second!" } + Write-Progress -Completed " " exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 -} +} \ No newline at end of file diff --git a/Scripts/check-drives.ps1 b/Scripts/check-drives.ps1 index 5fcb93ac..3b689c21 100755 --- a/Scripts/check-drives.ps1 +++ b/Scripts/check-drives.ps1 @@ -7,6 +7,7 @@ Specifies the minimum warning level (10 GB by default) .EXAMPLE PS> ./check-drives + ✅ Drive C uses 87GB of 249GB .LINK https://github.com/fleschutz/PowerShell .NOTES diff --git a/Scripts/check-gpu.ps1 b/Scripts/check-gpu.ps1 index 3f7f2f5d..2aa18601 100644 --- a/Scripts/check-gpu.ps1 +++ b/Scripts/check-gpu.ps1 @@ -38,6 +38,7 @@ try { $Status = $Details.Status Write-Host "✅ $Model GPU ($(Bytes2String $RAMSize) RAM, $($ResWidth)x$($ResHeight) pixels, $BitsPerPixel bit, $RefreshRate Hz, driver $DriverVersion, status $Status)" } + exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 diff --git a/Scripts/check-os.ps1 b/Scripts/check-os.ps1 index ea8b183e..1f718a60 100755 --- a/Scripts/check-os.ps1 +++ b/Scripts/check-os.ps1 @@ -15,7 +15,7 @@ try { if ($IsLinux) { $Name = $PSVersionTable.OS if ([System.Environment]::Is64BitOperatingSystem) { $Bits = "64-bit" } else { $Bits = "32-bit" } - "✅ $Name ($Bits)" + Write-Host "✅ $Name ($Bits)" } else { $OS = Get-WmiObject -class Win32_OperatingSystem $Name = $OS.Caption -Replace "Microsoft Windows","Windows" @@ -29,10 +29,10 @@ try { $InstallDate = $OSDetails.InstallDate $ProductKey = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" -Name BackupProductKeyDefault).BackupProductKeyDefault - "✅ $Name ($Arch, v$Version, S/N $Serial, P/K $ProductKey) since $($InstallDate.ToShortDateString())" + Write-Host "✅ $Name ($Arch, v$Version, S/N $Serial, P/K $ProductKey) since $($InstallDate.ToShortDateString())" } exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 -} +} \ No newline at end of file diff --git a/Scripts/check-pending-reboot.ps1 b/Scripts/check-pending-reboot.ps1 index 67651eae..0439fbe8 100644 --- a/Scripts/check-pending-reboot.ps1 +++ b/Scripts/check-pending-reboot.ps1 @@ -20,44 +20,48 @@ function Test-RegistryValue { param([parameter(Mandatory=$true)][ValidateNotNull } } -$Reason = "" - -if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired") { - $Reason += ", found registry entry '...\WindowsUpdate\Auto Update\RebootRequired'" +try { + $Reason = "" + if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired") { + $Reason += ", found registry entry '...\WindowsUpdate\Auto Update\RebootRequired'" + } + if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting") { + $Reason += ", found registry entry '...\WindowsUpdate\Auto Update\PostRebootReporting'" + } + if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending") { + $Reason += ", found registry entry '...\Component Based Servicing\RebootPending'" + } + if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts") { + $Reason += ", found registry entry '...\ServerManager\CurrentRebootAttempts'" + } + if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "RebootInProgress") { + $Reason += ", found registry entry '...\CurrentVersion\Component Based Servicing' with 'RebootInProgress'" + } + if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "PackagesPending") { + $Reason += ", found registry entry '...\CurrentVersion\Component Based Servicing' with 'PackagesPending'" + } + #if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations") { + # $Reason += ", found registry entry '...\CurrentControlSet\Control\Session Manager' with 'PendingFileRenameOperations'" + #} + if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations2") { + $Reason += ", found registry entry '...\CurrentControlSet\Control\Session Manager' with 'PendingFileRenameOperations2'" + } + if (Test-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" -Value "DVDRebootSignal") { + $Reason += ", found registry entry '...\Windows\CurrentVersion\RunOnce' with 'DVDRebootSignal'" + } + if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "JoinDomain") { + $Reason += ", found registry entry '...\CurrentControlSet\Services\Netlogon' with 'JoinDomain'" + } + if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "AvoidSpnSet") { + $Reason += ", found registry entry '...\CurrentControlSet\Services\Netlogon' with 'AvoidSpnSet'" + } + if ($Reason -ne "") { + Write-Host "⚠️ Pending reboot ($($Reason.substring(2)))" + } else { + Write-Host "✅ No pending reboot" + } + exit 0 # success +} catch { + "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 } -if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting") { - $Reason += ", found registry entry '...\WindowsUpdate\Auto Update\PostRebootReporting'" -} -if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending") { - $Reason += ", found registry entry '...\Component Based Servicing\RebootPending'" -} -if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts") { - $Reason += ", found registry entry '...\ServerManager\CurrentRebootAttempts'" -} -if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "RebootInProgress") { - $Reason += ", found registry entry '...\CurrentVersion\Component Based Servicing' with 'RebootInProgress'" -} -if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "PackagesPending") { - $Reason += ", found registry entry '...\CurrentVersion\Component Based Servicing' with 'PackagesPending'" -} -#if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations") { -# $Reason += ", found registry entry '...\CurrentControlSet\Control\Session Manager' with 'PendingFileRenameOperations'" -#} -if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations2") { - $Reason += ", found registry entry '...\CurrentControlSet\Control\Session Manager' with 'PendingFileRenameOperations2'" -} -if (Test-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" -Value "DVDRebootSignal") { - $Reason += ", found registry entry '...\Windows\CurrentVersion\RunOnce' with 'DVDRebootSignal'" -} -if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "JoinDomain") { - $Reason += ", found registry entry '...\CurrentControlSet\Services\Netlogon' with 'JoinDomain'" -} -if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "AvoidSpnSet") { - $Reason += ", found registry entry '...\CurrentControlSet\Services\Netlogon' with 'AvoidSpnSet'" -} -if ($Reason -ne "") { - "⚠️ Pending reboot ($($Reason.substring(2)))" -} else { - "✅ No pending reboot" -} -exit 0 # success diff --git a/Scripts/check-ping.ps1 b/Scripts/check-ping.ps1 index 800aef82..4b198750 100755 --- a/Scripts/check-ping.ps1 +++ b/Scripts/check-ping.ps1 @@ -17,11 +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 "⏳ (1/2) Pinging $hosts..." + Write-Progress "⏳ Pinging $hosts..." $HostsArray = $hosts.Split(",") $Pings = Test-Connection -count 1 -computerName $HostsArray - Write-Progress "⏳ (2/2) Calculating results..." + Write-Progress "⏳ Calculating results..." [int]$Min = 9999999 [int]$Max = [int]$Avg = 0 foreach($Ping in $Pings) { @@ -32,8 +32,8 @@ try { } $Avg /= $Pings.count + Write-Host "✅ Ping is $($Avg)ms average, $($Min)ms min, $($Max)ms max" Write-Progress -Completed " " - "✅ Ping is $($Avg)ms average, $($Min)ms min, $($Max)ms max" exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/check-powershell.ps1 b/Scripts/check-powershell.ps1 index 85240cc9..3dd94d9b 100644 --- a/Scripts/check-powershell.ps1 +++ b/Scripts/check-powershell.ps1 @@ -26,4 +26,4 @@ try { } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 -} +} \ No newline at end of file diff --git a/Scripts/check-smart-devices.ps1 b/Scripts/check-smart-devices.ps1 index ccc91cd7..cf240a21 100755 --- a/Scripts/check-smart-devices.ps1 +++ b/Scripts/check-smart-devices.ps1 @@ -5,7 +5,7 @@ This PowerShell script queries S.M.A.R.T. HDD/SSD device details and prints it. .EXAMPLE PS> ./check-smart-devices - ✅ 1TB Samsung SSD 970 EVO (via NVMe, 2388 hours, 289x on, v2B2QEXE7, 37°C, selftest passed) + ✅ 1TB Samsung SSD 970 EVO via NVMe (2388 hours, 289x on, v2B2QEXE7, 37°C, selftest passed) .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -29,18 +29,18 @@ function Bytes2String { param([int64]$Bytes) } try { - Write-Progress "⏳ Step 1/3 - Searching for smartctl executable..." + Write-Progress "⏳ Searching for smartctl executable..." $Result = (smartctl --version) if ($lastExitCode -ne "0") { throw "Can't execute 'smartctl' - make sure smartmontools are installed" } - Write-Progress "⏳ Step 2/3 - Scanning S.M.A.R.T devices..." + Write-Progress "⏳ Scanning S.M.A.R.T devices..." if ($IsLinux) { $Devices = $(sudo smartctl --scan-open) } else { $Devices = $(smartctl --scan-open) } foreach($Device in $Devices) { - Write-Progress "⏳ Step 3/3 - Querying S.M.A.R.T devices..." + Write-Progress "⏳ Querying S.M.A.R.T devices..." $Array = $Device.split(" ") $Device = $Array[0] if ("$Device" -eq "#") { @@ -65,8 +65,9 @@ try { $PowerOn = $Details.power_cycle_count $Hours = $Details.power_on_time.hours if ($Details.smart_status.passed) { $Status = "passed" } else { $Status = "FAILED" } - "✅ $($Capacity)$ModelName (via $Protocol, $Hours hours, $($PowerOn)x on, v$($Firmware), $($Temp)°C, selftest $Status)" + Write-Host "✅ $($Capacity)$ModelName via $Protocol ($Hours hours, $($PowerOn)x on, v$($Firmware), $($Temp)°C, selftest $Status)" } + Write-Progress -Completed " " exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/check-swap-space.ps1 b/Scripts/check-swap-space.ps1 index 17f1a4bb..bd677aa9 100755 --- a/Scripts/check-swap-space.ps1 +++ b/Scripts/check-swap-space.ps1 @@ -44,17 +44,17 @@ try { } } if ($Total -eq 0) { - "⚠️ No swap space configured!" + Write-Host "⚠️ No swap space configured!" } elseif ($Free -eq 0) { - "⚠️ Swap space of $(MB2String $Total) is full!" + Write-Host "⚠️ Swap space of $(MB2String $Total) is full!" } elseif ($Free -lt $MinLevel) { - "⚠️ Swap space of $(MB2String $Total) is nearly full ($(MB2String $Free) free)!" + Write-Host "⚠️ Swap space of $(MB2String $Total) is nearly full ($(MB2String $Free) free)!" } elseif ($Used -eq 0) { - "✅ Swap space with $(MB2String $Total) reserved" + Write-Host "✅ Swap space with $(MB2String $Total) reserved" } elseif ($Used -lt $Free) { - "✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)" + Write-Host "✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)" } else { - "✅ Swap space has $(MB2String $Free) of $(MB2String $Total) free" + Write-Host "✅ Swap space has $(MB2String $Free) of $(MB2String $Total) free" } exit 0 # success } catch { diff --git a/Scripts/check-vpn.ps1 b/Scripts/check-vpn.ps1 index 1e454513..3b2937f1 100755 --- a/Scripts/check-vpn.ps1 +++ b/Scripts/check-vpn.ps1 @@ -16,9 +16,9 @@ try { if ($IsLinux) { # TODO } else { - $Connections = (Get-VPNConnection) + $Connections = Get-VPNConnection foreach($Connection in $Connections) { - "✅ VPN '$($Connection.Name)' is $($Connection.ConnectionStatus)" + Write-Host "✅ VPN '$($Connection.Name)' is $($Connection.ConnectionStatus)" $NoVPN = $false } } @@ -27,4 +27,4 @@ try { } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 -} +} \ No newline at end of file