PowerShell help needed - SMART data parser from CrystalDiskInfo
Hello, colleagues,
as You may already have found out, the WMI-based HDD SMART data analysis lies and never tells a word about a HDD going to the silicon heaven. As the PDQ disk SMART status data are based on WMI, it lies as well.
When You compare the data with the output of CrystalDiskInfo, you find out, that SMART already has been shouting for years on many computers in the network while the PCs are reported slow by the end-users and after a thorough analysis you usually find unreadable or corrupted data on the drive. So I decided to act on this problem and want to use the reliable SMART analysis as the users' data are at risk and we do not know about it.
My aim is to create a Powershell scanner, that would run the previously installed CrystalDiskInfo in the CopyExit mode so that it spits out the output (done successfully) and parse the output into the columns in PDQ Inventory PS scanner output (this part I cannot do).
So first You install the CrystalDiskInfo, create a new PS scanner and run this:
Start-Process "$($Env:ProgramFiles)\CrystalDiskInfo\DiskInfo64.exe" -ArgumentList "/CopyExit" -wait
This spits out the TXT into >>> C:\Program Files\CrystalDiskInfo\DiskInfo.txt <<< .
I gathered CrystalDiskInfo outputs on two PCs in our network:
PC1 (tells everything it should)
>>>>>
----------------------------------------------------------------------------
CrystalDiskInfo 8.15.2 (C) 2008-2022 hiyohiyo
Crystal Dew World: https://crystalmark.info/
----------------------------------------------------------------------------
OS : Windows 10 [10.0 Build 19044] (x64)
Date : 2022/04/22 11:50:27
-- Controller Map ----------------------------------------------------------
+ Standardní řadič SATA AHCI [ATA]
- WDC WD2503ABYX-01WERA0
- HL-DT-ST DVDRAM GH24NSD1
- Řadič prostorů úložišť [SCSI]
-- Disk List ---------------------------------------------------------------
(01) WDC WD2503ABYX-01WERA0 : 251,0 GB [0/0/0, pd1]
----------------------------------------------------------------------------
(01) WDC WD2503ABYX-01WERA0
----------------------------------------------------------------------------
Model : WDC WD2503ABYX-01WERA0
Firmware : 01.01S01
Serial Number : WD-WMAYP2089873
Disk Size : 251,0 GB (8,4/137,4/251,0/251,0)
Buffer Size : Unknown
Queue Depth : 32
# of Sectors : 490350672
Rotation Rate : 7200 RPM
Interface : Serial ATA
Major Version : ATA8-ACS
Minor Version : ----
Transfer Mode : ---- | SATA/300
Power On Hours : 7575 hours
Power On Count : 672 count
Temperature : 38 C (100 F)
Health Status : Caution
Features : S.M.A.R.T., APM, NCQ
APM Level : 0080h [ON]
AAM Level : ----
Drive Letter : C:
-- S.M.A.R.T. --------------------------------------------------------------
ID Cur Wor Thr RawValues(6) Attribute Name
01 200 200 _51 00000000088B Read Error Rate
03 143 141 _21 000000000EF9 Spin-Up Time
04 100 100 __0 0000000002A2 Start/Stop Count
05 200 200 140 000000000000 Reallocated Sectors Count
07 200 200 __0 000000000000 Seek Error Rate
09 _90 _90 __0 000000001D97 Power-On Hours
0A 100 100 __0 000000000000 Spin Retry Count
0B 100 100 __0 000000000000 Recalibration Retries
0C 100 100 __0 0000000002A0 Power Cycle Count
C0 200 200 __0 0000000000A2 Power-off Retract Count
C1 200 200 __0 0000000001FF Load/Unload Cycle Count
C2 105 _99 __0 000000000026 Temperature
C4 200 200 __0 000000000000 Reallocation Event Count
C5 200 200 __0 000000000003 Current Pending Sector Count
C6 100 253 __0 000000000000 Uncorrectable Sector Count
C7 200 200 __0 000000000000 UltraDMA CRC Error Count
C8 100 253 __0 000000000000 Write Error Rate
-- IDENTIFY_DEVICE ---------------------------------------------------------
0 1 2 3 4 5 6 7 8 9
000: 427A 3FFF C837 0010 0000 0000 003F 0000 0000 0000
010: 2020 2020 2057 442D 574D 4159 5032 3038 3938 3733
020: 0000 0000 0032 3031 2E30 3153 3031 5744 4320 5744
030: 3235 3033 4142 5958 2D30 3157 4552 4130 2020 2020
040: 2020 2020 2020 2020 2020 2020 2020 8010 0000 2F00
050: 4001 0000 0000 0007 3FFF 0010 003F FC10 00FB 0110
060: FFFF 0FFF 0000 0007 0003 0078 0078 0078 0078 0000
070: 0000 0000 0000 0000 0000 001F 1D06 0000 0044 0040
080: 01FE 0000 746B 7D69 6163 7469 BC49 6163 207F 0014
090: 0014 0080 FFFE 0000 0000 0000 0000 0000 0000 0000
100: 2850 1D3A 0000 0000 0000 0000 0000 0000 5001 4EE0
110: 02E8 0CEE 0000 0000 0000 0000 0000 0000 0000 401C
120: 401C 0000 0000 0000 0000 0000 0000 0000 0029 0400
130: 0001 0000 0000 16FE 0122 0000 0000 0000 0000 0000
140: 0000 0000 0004 0000 0000 0000 0000 0000 0000 0000
150: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
160: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
170: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
180: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
190: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
200: 0000 0000 0000 0000 0000 0000 303F 0000 0000 0000
210: 0000 0000 0000 0000 0000 0000 0000 1C20 0000 0000
220: 0000 0000 101E 0000 0000 0000 0000 0000 0000 0000
230: 0000 0000 0000 0000 0001 1000 0000 0000 0000 0000
240: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
250: 0000 0000 0000 0000 0000 F7A5
-- SMART_READ_DATA ---------------------------------------------------------
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
000: 10 00 01 2F 00 C8 C8 8B 08 00 00 00 00 00 03 27
010: 00 8F 8D F9 0E 00 00 00 00 00 04 32 00 64 64 A2
020: 02 00 00 00 00 00 05 33 00 C8 C8 00 00 00 00 00
030: 00 00 07 2E 00 C8 C8 00 00 00 00 00 00 00 09 32
040: 00 5A 5A 97 1D 00 00 00 00 00 0A 32 00 64 64 00
050: 00 00 00 00 00 00 0B 32 00 64 64 00 00 00 00 00
060: 00 00 0C 32 00 64 64 A0 02 00 00 00 00 00 C0 32
070: 00 C8 C8 A2 00 00 00 00 00 00 C1 32 00 C8 C8 FF
080: 01 00 00 00 00 00 C2 22 00 69 63 26 00 00 00 00
090: 00 00 C4 32 00 C8 C8 00 00 00 00 00 00 00 C5 32
0A0: 00 C8 C8 03 00 00 00 00 00 00 C6 30 00 64 FD 00
0B0: 00 00 00 00 00 00 C7 32 00 C8 C8 00 00 00 00 00
0C0: 00 00 C8 08 00 64 FD 00 00 00 00 00 00 00 00 00
0D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
160: 00 00 00 00 00 00 00 00 00 00 84 00 F0 0F 01 7B
170: 03 00 01 00 02 2E 05 00 00 00 00 00 00 00 00 00
180: 00 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00
190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F5
-- SMART_READ_THRESHOLD ----------------------------------------------------
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
000: 10 00 01 33 C8 00 00 00 00 00 00 00 00 00 03 15
010: 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00
020: 00 00 00 00 00 00 05 8C 00 00 00 00 00 00 00 00
030: 00 00 07 00 C8 00 00 00 00 00 00 00 00 00 09 00
040: 00 00 00 00 00 00 00 00 00 00 0A 00 00 00 00 00
050: 00 00 00 00 00 00 0B 00 00 00 00 00 00 00 00 00
060: 00 00 0C 00 00 00 00 00 00 00 00 00 00 00 C0 00
070: 00 00 00 00 00 00 00 00 00 00 C1 00 00 00 00 00
080: 00 00 00 00 00 00 C2 00 00 00 00 00 00 00 00 00
090: 00 00 C4 00 00 00 00 00 00 00 00 00 00 00 C5 00
0A0: 00 00 00 00 00 00 00 00 00 00 C6 00 00 00 00 00
0B0: 00 00 00 00 00 00 C7 00 00 00 00 00 00 00 00 00
0C0: 00 00 C8 00 00 00 00 00 00 00 00 00 00 00 00 00
0D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
1F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2D
<<<<<
PC2 (tells nothing)
>>>>>>
----------------------------------------------------------------------------
CrystalDiskInfo 8.15.2 (C) 2008-2022 hiyohiyo
Crystal Dew World: https://crystalmark.info/
----------------------------------------------------------------------------
OS : Windows 10 [10.0 Build 19044] (x64)
Date : 2022/04/22 11:49:56
-- Controller Map ----------------------------------------------------------
+ Standardní řadič SATA AHCI [ATA]
- TOSHIBA A100
- HL-DT-ST DVDRAM GH24NSD1
- ATA Channel 0 (0) [ATA]
- ATA Channel 1 (1) [ATA]
+ PCI Standardní dvoukanálový řadič IDE [ATA]
- ATA Channel 0 (0)
- ATA Channel 1 (1)
- Řadič prostorů úložišť [SCSI]
-- Disk List ---------------------------------------------------------------
<<<<<<
The scanner should handle both situations (error handling).
Also it should handle more disks if present.
Could You please help me to parse this into PDQ?
In the beggining I am interested in the "Health status" the most, I can then connect to that machine and check it out manually. But the more data we can get from this TXT, the better analysis we can then do in the PDQ itself.
Thank You all very much.
Marek
Comments
Marek,
It looks like you are not the first person to try to tackle this issue in this way. Try using the method here:
https://www.cyberdrain.com/monitoring-with-powershell-smart-status-via-crystaldiskinfo/
Yes, Luke, that is surely true, however, this script does not pull any data into PDQ.
Marek,
I mistakenly assumed you were familiar with PDQ PowerShell scanners and just needed to solve getting the data from CrystalDiskInfo. I have been able to get all of the attributes of a single disk into a PDQ scanner with this:
Clear-Host
#Replace the Download URL to where you've uploaded the ZIP file yourself. We will only download this file once.
$DownloadURL = "\\server\name\CrystalDiskInfo8_16_4.zip"
$DownloadLocation = "$($Env:ProgramFiles)\CrystalDiskInfo"
#Script:
$TestDownloadLocation = Test-Path $DownloadLocation
if(!$TestDownloadLocation){
new-item $DownloadLocation -ItemType Directory -force
Invoke-WebRequest -Uri $DownloadURL -OutFile "$($DownloadLocation)\CrystalDiskInfo.zip"
Expand-Archive "$($DownloadLocation)\CrystalDiskInfo.zip" -DestinationPath $DownloadLocation -Force
}
#We start CrystalDiskInfo with the COPYEXIT parameter. This just collects the SMART information in DiskInfo.txt
Start-Process "$($Env:ProgramFiles)\CrystalDiskInfo\DiskInfo64.exe" -ArgumentList "/CopyExit" -wait
$DiskInfoRaw = get-content "$($Env:ProgramFiles)\CrystalDiskInfo\DiskInfo.txt" | select-string "-- S.M.A.R.T. --------------------------------------------------------------" -Context 0,15
$diskinfo = $DiskInfoRaw -split "`n" | select -skip 2 | Out-String | ConvertFrom-Csv -Delimiter " " -Header "Unused1","Unused2","ID","Cur","Wor","Thr","RawValue","AttributeName1","AttributeName2","AttributeName3","AttributeName4","AttributeName5"# | Select-Object ID,RawValue
$diskinfo = $diskinfo | Select-Object AttributeName1,AttributeName2,AttributeName3,AttributeName4,AttributeName5,RawValue
foreach ($Attribute in $diskinfo) {
[PSCustomObject]@{
AttributeName = ("$($Attribute.AttributeName1) $($Attribute.AttributeName2) $($Attribute.AttributeName3) $($Attribute.AttributeName4) $($Attribute.AttributeName5)").Trim()
Value = [UInt64]"0x$($Attribute.RawValue)"
}
}
Example output:
AttributeName Value
------------- -----
Reallocated Sector Count 1
Power-on Hours 74969
Power-on Count 321
Wear Leveling Count 27
Used Reserved Block Count (Total) 1
Program Fail Count (Total) 0
Erase Fail Count (Total) 1
Runtime Bad Block (Total) 1
Uncorrectable Error Count 0
Airflow Temperature 34
ECC Error Rate 0
CRC Error Count 0
POR Recovery Count 13
Total LBAs Written 73391344057
I had to make some changes to the script in the web page I linked because it did everything by attribute ID and all of those IDs were wrong for my environment. I switched to using attribute name which seems to work better. I also had to change the data type to [UInt64] because some of the attributes (namely Total LBAs written) did not fit in a [UInt32] data type.
Unfortunately this does not support multiple disks and does not grab the health status from the text file, but it's a starting point. I'll probably play around with this a bit more but since we don't use this in my environment I can't spend a lot of time on it. I hope this has helped you get to a starting point at least.