#Requires -RunAsAdministrator <# This gets drive health information from a local or remote computer It must be run as an administrator Alan Kaplan www.akaplan.com 6/17/20 Public version 12/24/21 #> [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$computer ) Try { $s = New-CimSession -ComputerName $computer -ErrorAction Stop } Catch { Write-Warning $_ Exit } Write-host "Getting disk information, please wait ..." -ForegroundColor green #fixed disks only $LogicalDisk = Get-CimInstance -Query "SELECT * FROM win32_logicaldisk WHERE DriveType = '3'" -CimSession $s #MSStorageDriver_FailurePredictStatus WMI class not available if MVME or older OS Try { $FPS = Get-CimInstance -Namespace root\wmi -ClassName MSStorageDriver_FailurePredictStatus -CimSession $s -ErrorAction Stop $Remarks = '' } Catch { $Remarks = "Failure Prediction Status not available" } #Associated instances hurt my head @(foreach ($ld in $LogicalDisk) { $drvltr = $ld.DeviceID $Size = [math]::round($ld.size / 1GB, 2) $free = [math]::round($ld.FreeSpace / 1GB, 2) $pctFree = ($free / $size).ToString("P") #Get drive from logical disk $DriveLD = Get-CimInstance -classname win32_logicaldisk -Filter "Name='$drvltr'" -CimSession $s | Get-CimAssociatedInstance -ResultClassName Win32_DiskPartition | Get-CimAssociatedInstance -ResultClassName Win32_diskdrive $PNPDeviceID = $DriveLD.PNPDeviceID $predict = $FPS | Where-Object { $_.InstanceName -like "$PNPDeviceid*" } $SupportsSMART = $driveld.Capabilities -contains 10 #Get Read Errors and hours on from storage reliablity counters, by physical disk $SR = Get-PhysicalDisk -DeviceNumber $DriveLD.Index -CimSession $s | Get-StorageReliabilityCounter -CimSession $s #Create an ordered hashtable, later converted to PSCustomObject $o = [ordered]@{ Drive = $drvltr Size_GB = $size Free_GB = $free PctFree = $pctFree Model = $DriveLD.Model } if ($null -ne $SR.PowerOnHours) { $o.Add('ReadErrorsTotal' , $SR.ReadErrorsTotal) $o.Add('ReadErrorsCorrected' , $SR.ReadErrorsCorrected) $o.Add('PowerOnHours' , $sr.PowerOnHours) $o.Add('PowerOnYears' , [math]::Round(($sr.PowerOnHours / 24 / 365) , 2)) } $o.Add('DeviceID', $DriveLD.DeviceID) $o.Add('Firmware', $DriveLD.FirmwareRevision) $o.Add('SN' , [string]($DriveLD.SerialNumber).trim()) $o.Add('SMART' , $SupportsSMART) if ($SupportsSMART) { $WillFail = $predict.PredictFailure $o.Add('PredictFailure', $WillFail) if ($WillFail) { $o.Add('Reason', $predict.Reason) } } if ($Remarks -ne '') { $o.Add('Remarks', $Remarks) } #Convert Hashtable to PScustomObject [PSCustomObject]$o } ) | Out-GridView -wait -Title "Disk information $computer, selected items sent to clipboard" | set-clipboard