mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-08 17:14:28 +01:00
Add check-smart-devices.ps1
This commit is contained in:
parent
8b6993561a
commit
6587c05642
37
Scripts/check-smart-devices.ps1
Executable file
37
Scripts/check-smart-devices.ps1
Executable file
@ -0,0 +1,37 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
check-smart-devices.ps1
|
||||
.DESCRIPTION
|
||||
Performs a short selftest on your S.M.A.R.T. HDD/SSD devices.
|
||||
Requires smartctl (smartmontools) and admin rights.
|
||||
.EXAMPLE
|
||||
PS> ./check-smart-devices
|
||||
.NOTES
|
||||
Author: Markus Fleschutz · License: CC0
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
#>
|
||||
|
||||
#Requires -RunAsAdministrator
|
||||
|
||||
try {
|
||||
"Step 1/4: Checking for 'smartctl'..."
|
||||
$Result=(smartctl --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'smartctl' - make sure smartmontools are installed" }
|
||||
|
||||
"Step 2/4: Scanning for S.M.A.R.T. devices..."
|
||||
$Devices = $(sudo smartctl --scan-open)
|
||||
|
||||
foreach($Device in $Devices) {
|
||||
$Array = $Device.split(" ")
|
||||
$Device = $Array[0]
|
||||
"Step 3/4: Starting short selftest on device $Device..."
|
||||
& sudo smartctl --test=short $Device
|
||||
}
|
||||
|
||||
"✔️ Done."
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
||||
exit 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user