mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-29 22:48:50 +02:00
Update check-smart-devices.ps1
This commit is contained in:
parent
4e93ed99bd
commit
fbdddbabe8
@ -17,12 +17,10 @@
|
|||||||
& "$PSScriptRoot/check-ram.ps1"
|
& "$PSScriptRoot/check-ram.ps1"
|
||||||
& "$PSScriptRoot/check-swap-space.ps1"
|
& "$PSScriptRoot/check-swap-space.ps1"
|
||||||
& "$PSScriptRoot/check-time-zone.ps1"
|
& "$PSScriptRoot/check-time-zone.ps1"
|
||||||
|
& "$PSScriptRoot/check-smart-devices.ps1"
|
||||||
& "$PSScriptRoot/check-drives.ps1"
|
& "$PSScriptRoot/check-drives.ps1"
|
||||||
& "$PSScriptRoot/check-dns.ps1"
|
& "$PSScriptRoot/check-dns.ps1"
|
||||||
& "$PSScriptRoot/check-ping.ps1"
|
& "$PSScriptRoot/check-ping.ps1"
|
||||||
& "$PSScriptRoot/check-vpn.ps1"
|
& "$PSScriptRoot/check-vpn.ps1"
|
||||||
if ($IsLinux) {
|
|
||||||
& "$PSScriptRoot/check-smart-devices.ps1"
|
|
||||||
}
|
|
||||||
& "$PSScriptRoot/check-pending-reboot.ps1"
|
& "$PSScriptRoot/check-pending-reboot.ps1"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -1,34 +1,45 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Performs a selftest on your S.M.A.R.T. HDD/SSD devices.
|
Checks S.M.A.R.T. devices
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script performs a selftest on your S.M.A.R.T. HDD/SSD devices.
|
This PowerShell script queries and prints your S.M.A.R.T. HDD/SSD devices.
|
||||||
It requires smartctl (smartmontools package) and admin rights.
|
|
||||||
.PARAMETER type
|
|
||||||
Specifies the type of selftest: either short (default) or long
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./check-smart-devices
|
PS> ./check-smart-devices
|
||||||
✅ Started short selftest on S.M.A.R.T. device /dev/sda
|
✅ Device HFM256GD3JX016N (SMART nvme), 238GB, 126x on, 71h, 29°C, passed
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
#Requires -RunAsAdministrator
|
|
||||||
|
|
||||||
param([string]$type = "short")
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Result=(smartctl --version)
|
Write-Progress "⏳ Step 1/3 - Searching for 'smartctl'..."
|
||||||
|
$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" }
|
||||||
|
|
||||||
$Devices = $(sudo smartctl --scan-open)
|
Write-Progress "⏳ Step 2/3 - Scanning S.M.A.R.T devices..."
|
||||||
|
if ($IsLinux) {
|
||||||
|
$Devices = $(sudo smartctl --scan-open)
|
||||||
|
} else {
|
||||||
|
$Devices = $(smartctl --scan-open)
|
||||||
|
}
|
||||||
foreach($Device in $Devices) {
|
foreach($Device in $Devices) {
|
||||||
|
Write-Progress "⏳ Step 3/3 - Querying S.M.A.R.T devices..."
|
||||||
$Array = $Device.split(" ")
|
$Array = $Device.split(" ")
|
||||||
$Device = $Array[0]
|
$Device = $Array[0]
|
||||||
$Result = (sudo smartctl --test=$type $Device)
|
if ($IsLinux) {
|
||||||
"✅ Started $type selftest on S.M.A.R.T. device $Device"
|
$Details = (sudo smartctl --all --json $Device) | ConvertFrom-Json
|
||||||
|
} else {
|
||||||
|
$Details = (smartctl --all --json $Device) | ConvertFrom-Json
|
||||||
|
}
|
||||||
|
$ModelName = $Details.model_name
|
||||||
|
$Type = $Details.device.type
|
||||||
|
[int]$Capacity = $Details.user_capacity.bytes / (1024 * 1024 * 1024)
|
||||||
|
$Temp = $Details.temperature.current
|
||||||
|
$PowerOn = $Details.power_cycle_count
|
||||||
|
$Hours = $Details.power_on_time.hours
|
||||||
|
if ($Details.smart_status.passed) { $Status = "passed" } else { $Status = "NOT PASSED" }
|
||||||
|
"✅ Device $ModelName (SMART $Type), $($Capacity)GB, $($PowerOn)x on, $($Hours)h, $($Temp)°C, $Status"
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user