PowerShell/Scripts/check-smart-devices.ps1

38 lines
1.1 KiB
PowerShell
Raw Normal View History

2021-10-03 21:32:17 +02:00
<#
.SYNOPSIS
2021-10-04 21:29:23 +02:00
Performs a selftest on your S.M.A.R.T. HDD/SSD devices.
2021-10-03 21:32:17 +02:00
.DESCRIPTION
2021-10-16 16:50:10 +02:00
This script performs a selftest on 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
2021-10-03 21:32:17 +02:00
.EXAMPLE
PS> ./check-smart-devices
2021-10-03 21:43:29 +02:00
short selftest started on S.M.A.R.T. device /dev/sda
2021-10-03 21:32:17 +02:00
.NOTES
Author: Markus Fleschutz · License: CC0
.LINK
https://github.com/fleschutz/PowerShell
#>
#Requires -RunAsAdministrator
2021-10-03 21:43:29 +02:00
param([string]$type = "short")
2021-10-03 21:32:17 +02:00
try {
$Result=(smartctl --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'smartctl' - make sure smartmontools are installed" }
$Devices = $(sudo smartctl --scan-open)
foreach($Device in $Devices) {
$Array = $Device.split(" ")
$Device = $Array[0]
2021-10-03 21:43:29 +02:00
$Result = (sudo smartctl --test=$type $Device)
"✔️ $type selftest started on S.M.A.R.T. device $Device"
2021-10-03 21:32:17 +02:00
}
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}