Updated some check-*.ps1 scripts

This commit is contained in:
Markus Fleschutz 2023-01-01 19:22:35 +01:00
parent f71ce2419d
commit 0cef271a29
13 changed files with 82 additions and 74 deletions

View File

@ -15,7 +15,7 @@ try {
if ($IsLinux) { if ($IsLinux) {
# TODO # TODO
} else { } else {
Write-Progress "(1/2) Querying installed apps (for current user only)..." Write-Progress "Querying installed apps..."
$Apps = Get-AppxPackage $Apps = Get-AppxPackage
[int]$NumInstalled = $Apps.Count [int]$NumInstalled = $Apps.Count
[int]$NumIssues = 0 [int]$NumIssues = 0
@ -23,12 +23,12 @@ try {
if ($App.Status -ne "Ok") { $NumIssues++ } 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 $NumUpdates = (winget upgrade --include-unknown).Count - 5
Write-Progress -Completed " "
[int]$NumErrors = (Get-AppxLastError) [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 exit 0 # success
} catch { } catch {

View File

@ -30,7 +30,7 @@ try {
if ($Remaining -lt 30) { $Status = "⚠️" } if ($Remaining -lt 30) { $Status = "⚠️" }
$Battery = "$Percent% battery life, $Remaining min. left" $Battery = "$Percent% battery life, $Remaining min. left"
} }
"$Status $Power, $Battery" Write-Host "$Status $Power, $Battery"
} }
exit 0 # success exit 0 # success
} catch { } catch {

View File

@ -30,7 +30,7 @@ function GetCPUTemperatureInCelsius {
} }
try { try {
Write-Progress "Querying CPU details ..." Write-Progress "Querying CPU details ..."
$Status = "" $Status = ""
$Celsius = GetCPUTemperatureInCelsius $Celsius = GetCPUTemperatureInCelsius
if ($Celsius -eq 99999.9) { if ($Celsius -eq 99999.9) {
@ -68,6 +68,7 @@ try {
} }
$Cores = [System.Environment]::ProcessorCount $Cores = [System.Environment]::ProcessorCount
Write-Host "$Status $CPUName ($Cores cores, $($DeviceID)$($Speed)$($Socket)$Temp)" Write-Host "$Status $CPUName ($Cores cores, $($DeviceID)$($Speed)$($Socket)$Temp)"
Write-Progress -Completed " "
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 {
Write-Progress "(1/2) Loading Data/popular-domains.csv..." Write-Progress "Loading Data/popular-domains.csv..."
$Table = Import-CSV "$PSScriptRoot/../Data/popular-domains.csv" $Table = Import-CSV "$PSScriptRoot/../Data/popular-domains.csv"
$NumRows = $Table.Length $NumRows = $Table.Length
Write-Progress "(2/2) Resolving $NumRows domains..." Write-Progress "Resolving $NumRows domains..."
$StopWatch = [system.diagnostics.stopwatch]::startNew() $StopWatch = [system.diagnostics.stopwatch]::startNew()
if ($IsLinux) { if ($IsLinux) {
foreach($Row in $Table){$nop=dig $Row.Domain +short} foreach($Row in $Table){$nop=dig $Row.Domain +short}
@ -25,15 +25,15 @@ try {
} }
[float]$Elapsed = $StopWatch.Elapsed.TotalSeconds [float]$Elapsed = $StopWatch.Elapsed.TotalSeconds
Write-Progress -Completed " "
$Average = [math]::round($NumRows / $Elapsed, 1) $Average = [math]::round($NumRows / $Elapsed, 1)
if ($Average -gt 100.0) { 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) { } elseif ($Average -gt 10.0) {
"✅ DNS resolves $Average domains per second" Write-Host "✅ DNS resolves $Average domains per second"
} else { } else {
"⚠️ DNS resolves only $Average domains per second!" Write-Host "⚠️ DNS resolves only $Average domains per second!"
} }
Write-Progress -Completed " "
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,6 +7,7 @@
Specifies the minimum warning level (10 GB by default) Specifies the minimum warning level (10 GB by default)
.EXAMPLE .EXAMPLE
PS> ./check-drives PS> ./check-drives
Drive C uses 87GB of 249GB
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES

View File

@ -38,6 +38,7 @@ try {
$Status = $Details.Status $Status = $Details.Status
Write-Host "$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)"
} }
exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1

View File

@ -15,7 +15,7 @@ try {
if ($IsLinux) { if ($IsLinux) {
$Name = $PSVersionTable.OS $Name = $PSVersionTable.OS
if ([System.Environment]::Is64BitOperatingSystem) { $Bits = "64-bit" } else { $Bits = "32-bit" } if ([System.Environment]::Is64BitOperatingSystem) { $Bits = "64-bit" } else { $Bits = "32-bit" }
"$Name ($Bits)" Write-Host "$Name ($Bits)"
} else { } else {
$OS = Get-WmiObject -class Win32_OperatingSystem $OS = Get-WmiObject -class Win32_OperatingSystem
$Name = $OS.Caption -Replace "Microsoft Windows","Windows" $Name = $OS.Caption -Replace "Microsoft Windows","Windows"
@ -29,7 +29,7 @@ try {
$InstallDate = $OSDetails.InstallDate $InstallDate = $OSDetails.InstallDate
$ProductKey = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" -Name BackupProductKeyDefault).BackupProductKeyDefault $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 exit 0 # success
} catch { } catch {

View File

@ -20,8 +20,8 @@ function Test-RegistryValue { param([parameter(Mandatory=$true)][ValidateNotNull
} }
} }
try {
$Reason = "" $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") {
$Reason += ", found registry entry '...\WindowsUpdate\Auto Update\RebootRequired'" $Reason += ", found registry entry '...\WindowsUpdate\Auto Update\RebootRequired'"
} }
@ -56,8 +56,12 @@ if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon"
$Reason += ", found registry entry '...\CurrentControlSet\Services\Netlogon' with 'AvoidSpnSet'" $Reason += ", found registry entry '...\CurrentControlSet\Services\Netlogon' with 'AvoidSpnSet'"
} }
if ($Reason -ne "") { if ($Reason -ne "") {
"⚠️ Pending reboot ($($Reason.substring(2)))" Write-Host "⚠️ Pending reboot ($($Reason.substring(2)))"
} else { } else {
"✅ No pending reboot" Write-Host "✅ No pending reboot"
} }
exit 0 # success exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -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") param([string]$hosts = "amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com")
try { try {
Write-Progress "(1/2) Pinging $hosts..." Write-Progress "Pinging $hosts..."
$HostsArray = $hosts.Split(",") $HostsArray = $hosts.Split(",")
$Pings = Test-Connection -count 1 -computerName $HostsArray $Pings = Test-Connection -count 1 -computerName $HostsArray
Write-Progress "(2/2) Calculating results..." Write-Progress "Calculating results..."
[int]$Min = 9999999 [int]$Min = 9999999
[int]$Max = [int]$Avg = 0 [int]$Max = [int]$Avg = 0
foreach($Ping in $Pings) { foreach($Ping in $Pings) {
@ -32,8 +32,8 @@ try {
} }
$Avg /= $Pings.count $Avg /= $Pings.count
Write-Host "✅ Ping is $($Avg)ms average, $($Min)ms min, $($Max)ms max"
Write-Progress -Completed " " Write-Progress -Completed " "
"✅ Ping is $($Avg)ms average, $($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

@ -5,7 +5,7 @@
This PowerShell script queries S.M.A.R.T. HDD/SSD device details and prints it. This PowerShell script queries S.M.A.R.T. HDD/SSD device details and prints it.
.EXAMPLE .EXAMPLE
PS> ./check-smart-devices 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 .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -29,18 +29,18 @@ function Bytes2String { param([int64]$Bytes)
} }
try { try {
Write-Progress "⏳ Step 1/3 - Searching for smartctl executable..." Write-Progress "⏳ Searching for smartctl executable..."
$Result = (smartctl --version) $Result = (smartctl --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'smartctl' - make sure smartmontools are installed" } 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) { if ($IsLinux) {
$Devices = $(sudo smartctl --scan-open) $Devices = $(sudo smartctl --scan-open)
} else { } else {
$Devices = $(smartctl --scan-open) $Devices = $(smartctl --scan-open)
} }
foreach($Device in $Devices) { 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(" ") $Array = $Device.split(" ")
$Device = $Array[0] $Device = $Array[0]
if ("$Device" -eq "#") { if ("$Device" -eq "#") {
@ -65,8 +65,9 @@ try {
$PowerOn = $Details.power_cycle_count $PowerOn = $Details.power_cycle_count
$Hours = $Details.power_on_time.hours $Hours = $Details.power_on_time.hours
if ($Details.smart_status.passed) { $Status = "passed" } else { $Status = "FAILED" } 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 exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -44,17 +44,17 @@ try {
} }
} }
if ($Total -eq 0) { if ($Total -eq 0) {
"⚠️ No swap space configured!" Write-Host "⚠️ No swap space configured!"
} elseif ($Free -eq 0) { } elseif ($Free -eq 0) {
"⚠️ Swap space of $(MB2String $Total) is full!" Write-Host "⚠️ Swap space of $(MB2String $Total) is full!"
} elseif ($Free -lt $MinLevel) { } 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) { } elseif ($Used -eq 0) {
"✅ Swap space with $(MB2String $Total) reserved" Write-Host "✅ Swap space with $(MB2String $Total) reserved"
} elseif ($Used -lt $Free) { } elseif ($Used -lt $Free) {
"✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)" Write-Host "✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)"
} else { } else {
"✅ Swap space has $(MB2String $Free) of $(MB2String $Total) free" Write-Host "✅ Swap space has $(MB2String $Free) of $(MB2String $Total) free"
} }
exit 0 # success exit 0 # success
} catch { } catch {

View File

@ -16,9 +16,9 @@ try {
if ($IsLinux) { if ($IsLinux) {
# TODO # TODO
} else { } else {
$Connections = (Get-VPNConnection) $Connections = Get-VPNConnection
foreach($Connection in $Connections) { foreach($Connection in $Connections) {
"✅ VPN '$($Connection.Name)' is $($Connection.ConnectionStatus)" Write-Host "✅ VPN '$($Connection.Name)' is $($Connection.ConnectionStatus)"
$NoVPN = $false $NoVPN = $false
} }
} }