POSH-DiskHealth.ps1
#Requires -RunAsAdministrator #Requires -Version 4 <#PSScriptInfo .DESCRIPTION Performs multiple checks of local disks to predict if a disk might need replacing. Windows 8/Server 2012+. .VERSION 1.1.0.0 .GUID ca58874b-60b2-4177-8749-3771db294d1a .AUTHOR Gavin Eke @GavinEke .TAGS POSH-DiskHealth .RELEASENOTES https://github.com/GavinEke/POSH-DiskHealth #> Function Test-Administrator { $AdminUserTest = [Security.Principal.WindowsIdentity]::GetCurrent(); (New-Object Security.Principal.WindowsPrincipal $AdminUserTest).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) } If ((Test-Administrator -eq $True) -and ([Environment]::OSVersion.Version.Major -ge 6)) { #Prerequisite Check [regex]$regex = "4&[0-f]{8}&0&0[0-f]0{4}" ForEach ($UniqueDriveID in ((Get-Disk).ObjectId | Select-String -Pattern $regex).Matches.Value) { $Disk = Get-Disk | Where-Object ObjectId -Like "*$UniqueDriveID*" $DiskHealthStats = Get-Disk -Number $Disk.Number | Get-StorageReliabilityCounter $FailurePredict = Get-CimInstance -Namespace root\wmi -Class MSStorageDriver_FailurePredictStatus | Where-Object InstanceName -Like "*$UniqueDriveID*" Write-Output "====================================================" Write-Output "Disk No. $($Disk.Number)" Write-Output "Disk Name: $($Disk.FriendlyName)" Write-Output "Disk S/N: $($Disk.SerialNumber)" Write-Output "----------------------------------------------------" Write-Output "Disk is $($Disk.HealthStatus)" If ($DiskHealthStats.Wear -gt 90) { Write-Output "SSD is very close to end of life. You should replace this SSD ASAP" } ElseIf ($DiskHealthStats.Wear -gt 80) { Write-Output "SSD is close to end of life. You should consider replacing this SSD" } Write-Output "Read Error Count is $($DiskHealthStats.ReadErrorsTotal)" Write-Output "Read Errors Corrected is $($DiskHealthStats.ReadErrorsCorrected)" Write-Output "Failure Predicted: $($FailurePredict.PredictFailure)" If ($FailurePredict.PredictFailure -eq $True) { Write-Output "Failure Predicted Reason: $($FailurePredict.Reason)" } Write-Output "====================================================" Write-Output "" } } Else { Write-Error "Prerequisite Check Failed - This script can only be run on Windows 8/Server 2012+ in an elevated shell" } |