From 289983d88894c26065cc4c667b5d2e14839f3fbf Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Thu, 27 Oct 2022 16:55:32 +0200 Subject: [PATCH] Update check-smart-devices.ps1 --- Scripts/check-smart-devices.ps1 | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Scripts/check-smart-devices.ps1 b/Scripts/check-smart-devices.ps1 index 49aaf394..32c51c0e 100755 --- a/Scripts/check-smart-devices.ps1 +++ b/Scripts/check-smart-devices.ps1 @@ -12,6 +12,22 @@ Author: Markus Fleschutz | License: CC0 #> +function Bytes2String { param([int64]$Bytes) + if ($Bytes -lt 1000) { return "$Bytes bytes" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)KB" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)MB" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)GB" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)TB" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)PB" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)EB" } +} + try { Write-Progress "⏳ Step 1/3 - Searching for smartctl executable..." $Result = (smartctl --version) @@ -36,18 +52,18 @@ try { } $ModelName = $Details.model_name $Protocol = $Details.device.protocol - [int]$GBytes = $Details.user_capacity.bytes / (1000 * 1000 * 1000) - if ($GBytes -eq 0) { - $Capacity = "" + [int64]$GBytes = $Details.user_capacity.bytes + if ($GBytes -gt 0) { + $Capacity = "$(Bytes2String $GBytes) " } else { - $Capacity = "($($GBytes)GB) " + $Capacity = "" } $Temp = $Details.temperature.current $Firmware = $Details.firmware_version $PowerOn = $Details.power_cycle_count $Hours = $Details.power_on_time.hours if ($Details.smart_status.passed) { $Status = "passed" } else { $Status = "FAILED" } - "✅ Device $ModelName $($Capacity)via $Protocol, $($Temp)°C, $($Hours) hours, $($PowerOn)x on, v$($Firmware), selftest $Status." + "✅ $($Capacity)$ModelName via $Protocol, $($Temp)°C, $($Hours) hours, $($PowerOn)x on, v$($Firmware), selftest $Status." } exit 0 # success } catch {