forked from fleschutz/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-smart-devices.ps1
More file actions
executable file
·37 lines (33 loc) · 1.05 KB
/
Copy pathcheck-smart-devices.ps1
File metadata and controls
executable file
·37 lines (33 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<#
.SYNOPSIS
Performs a selftest on your S.M.A.R.T. HDD/SSD devices.
.DESCRIPTION
This PowerShell 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
.EXAMPLE
PS> ./check-smart-devices
✔️ short selftest started on S.M.A.R.T. device /dev/sda
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#Requires -RunAsAdministrator
param([string]$type = "short")
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]
$Result = (sudo smartctl --test=$type $Device)
"✔️ $type selftest started on S.M.A.R.T. device $Device"
}
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}