Is it possible to run CrystalDiskInfo from the command line/powershell?
that script above is very supportive!
any chance to split the report into separate files for each DRIVE (file name = serial number). I tried that, but failed with splitting the file (now, every file contains ALL drive CDi values (besides posting the numbers block twice, surprisingly)).
thanks for help :)
# Define the report path
$ReportPath = "C:\share\_run\CDi CLi\reports"
Create the reports directory if it doesn't exist
if (-not (Test-Path $ReportPath)) {
New-Item -Path $ReportPath -ItemType Directory -Force | Out-Null
}
Path and execution of CrystalDiskInfo
$cdiskinfo="C:\Program Files\CrystalDiskInfo"
& "$cdiskinfo\DiskInfo64.exe" /CopyExit
$s=gc "$cdiskinfo\DiskInfo.txt"
Extract serial numbers to create folders
$serialMatches = $s | Select-String " Serial Number : (.+)$"
$serials = $serialMatches | ForEach-Object { $_.Matches.Groups[1].Value.Trim() }
Get current timestamp
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Get the header information (everything before the first drive details)
$headerContent = [System.Collections.ArrayList]@()
$foundFirstDrive = $false
foreach ($line in $s) {
if ($line -match "^-{20,} (\d+) ") {
$foundFirstDrive = $true
break
}
$headerContent.Add($line) | Out-Null
}
Process the output for each drive
$currentSerial = $null
$currentContent = [System.Collections.ArrayList]@()
$isFirstDrive = $true
foreach ($line in $s) {
# Check if this is a new drive section
if ($line -match "^-{20,}$" -or $line -match "^-{20,} (\d+) ") {
# If we have collected content for a drive, save it
if ($currentSerial -and $currentContent.Count -gt 0) {
# Create folder for the drive
$driveFolder = Join-Path -Path $ReportPath -ChildPath $currentSerial
if (-not (Test-Path $driveFolder)) {
New-Item -Path $driveFolder -ItemType Directory -Force | Out-Null
}
# Save the content with header
$fileName = "CDi CLi - $currentSerial.txt"
$filePath = Join-Path -Path $driveFolder -ChildPath $fileName
# Add timestamp separator if file exists
if (Test-Path $filePath) {
"`n`n===========================================================" | Out-File -FilePath $filePath -Encoding UTF8 -Append
"Report Date: $timestamp" | Out-File -FilePath $filePath -Encoding UTF8 -Append
"===========================================================`n" | Out-File -FilePath $filePath -Encoding UTF8 -Append
}
# Combine header and drive content
$fullContent = [System.Collections.ArrayList]@()
$headerContent | ForEach-Object { $fullContent.Add($_) | Out-Null }
$currentContent | ForEach-Object { $fullContent.Add($_) | Out-Null }
# Write or append to file
if (Test-Path $filePath) {
$fullContent | Out-File -FilePath $filePath -Encoding UTF8 -Append
} else {
$fullContent | Out-File -FilePath $filePath -Encoding UTF8
}
}
# Reset for next drive
$currentContent = [System.Collections.ArrayList]@()
$currentSerial = $null
}
# Add line to current content
$currentContent.Add($line) | Out-Null
# Check if this line contains a serial number
if ($line -match " Serial Number : (.+)$") {
$currentSerial = $matches[1].Trim()
}
}
Save the last drive's content if exists
if ($currentSerial -and $currentContent.Count -gt 0) {
$driveFolder = Join-Path -Path $ReportPath -ChildPath $currentSerial
if (-not (Test-Path $driveFolder)) {
New-Item -Path $driveFolder -ItemType Directory -Force | Out-Null
}
$fileName = "CDi CLi - $currentSerial.txt"
$filePath = Join-Path -Path $driveFolder -ChildPath $fileName
# Add timestamp separator if file exists
if (Test-Path $filePath) {
"`n`n===========================================================" | Out-File -FilePath $filePath -Encoding UTF8 -Append
"Report Date: $timestamp" | Out-File -FilePath $filePath -Encoding UTF8 -Append
"===========================================================`n" | Out-File -FilePath $filePath -Encoding UTF8 -Append
}
# Combine header and drive content
$fullContent = [System.Collections.ArrayList]@()
$headerContent | ForEach-Object { $fullContent.Add($_) | Out-Null }
$currentContent | ForEach-Object { $fullContent.Add($_) | Out-Null }
# Write or append to file
if (Test-Path $filePath) {
$fullContent | Out-File -FilePath $filePath -Encoding UTF8 -Append
} else {
$fullContent | Out-File -FilePath $filePath -Encoding UTF8
}
}
Extract basic info for display
$models=($s | select-string " Model : (.+)$" | ForEach-Object { $.Matches.Groups[1].Value.Trim() })
$firmwares=($s | select-string " Firmware : (.+)$" | ForEach-Object { $.Matches.Groups[1].Value.Trim() })
$healths=($s | Select-String " Health Status : (.+)$" | ForEach-Object { $.Matches.Groups[1].Value.Trim() })
$dletters=($s | Select-String " Drive Letter : (.+)$" | ForEach-Object { $.Matches.Groups[1].Value.Trim() })
$temps=($s | Select-String " Temperature : (.+)$" | ForEach-Object { $.Matches.Groups[1].Value.Trim() })
$feats=($s | Select-String " Features : (.+)$" | ForEach-Object { $.Matches.Groups[1].Value.Trim() })
Create and display drive objects
$Drives = for ($i=0;$i -lt $models.count;$i++) {
[PSCustomObject]@{
"Model"=$models[$i]
"Firmware"=$firmwares[$i]
"Health"=$healths[$i]
"Letter"=$dletters[$i]
"Temp"=$temps[$i]
"Features"=$feats[$i]
"Serial"=$serials[$i]
}
}
Display drives information in console
$Drives