Skip to content

Instantly share code, notes, and snippets.

@padajo
Last active May 14, 2025 11:14
Show Gist options
  • Save padajo/05ba3a70cc85f495f8abd335bc0cd979 to your computer and use it in GitHub Desktop.
Save padajo/05ba3a70cc85f495f8abd335bc0cd979 to your computer and use it in GitHub Desktop.
Simple SD card checker for initial few GB of drive to do a basic check to see if a card is fake or not
# For Windows Powershell
# This program (created by ChatGPT) checks the integrity of an SD card by creating a large test file, copying it to a specified location, and comparing the two files.
# It prompts the user for the SD card drive letter and destination folder, and allows the user to create the destination folder if it doesn't exist.
# Prompt user for drive letter and destination folder
$driveLetter = Read-Host "Enter the drive letter of the SD card (e.g. E:)"
$destinationFolder = Read-Host "Enter the full path to copy the file to (e.g. C:\Users\YourName\Desktop)"
$testSizeGB = Read-Host "Enter test file size in GB (default is 8GB)"
if (-not $testSizeGB) { $testSizeGB = 8 }
[int]$testSizeGB = $testSizeGB
$blockCount = $testSizeGB * 1024 # 1MB blocks
# --- Validate SD card drive ---
if (-not (Test-Path "$driveLetter\")) {
Write-Error "Drive $driveLetter not found or inaccessible."
exit 1
}
# --- Validate destination folder ---
if (-not (Test-Path $destinationFolder)) {
Write-Warning "Destination folder does not exist: $destinationFolder"
$create = Read-Host "Would you like to create it? (Y/N)"
if ($create -match '^[Yy]$') {
try {
New-Item -ItemType Directory -Path $destinationFolder -Force | Out-Null
Write-Output "✅ Created destination folder."
} catch {
Write-Error "❌ Could not create the folder: $_"
exit 1
}
} else {
Write-Output "❌ Aborting. Destination folder must exist."
exit 1
}
}
# Set file paths
$sourcePath = Join-Path "$driveLetter\" "sdcard_testfile_${testSizeGB}gb.bin"
$destinationPath = Join-Path $destinationFolder "sdcard_testfile_${testSizeGB}gb_copy.bin"
Write-Output "Creating ${testSizeGB}GB file on $driveLetter..."
$buffer = New-Object byte[] (1MB)
$rnd = New-Object System.Random
# Write test file
[System.IO.File]::OpenWrite($sourcePath) | ForEach-Object {
$i = 0
while ($i -lt $blockCount) {
$rnd.NextBytes($buffer)
$_.Write($buffer, 0, $buffer.Length)
$i++
if ($i % 512 -eq 0) { Write-Progress -Activity "Writing..." -Status "$i MB written..." -PercentComplete ($i / $blockCount * 100) }
}
$_.Close()
}
Write-Output "✅ File created at $sourcePath."
# Copy to destination
Write-Output "Copying file to $destinationPath..."
Copy-Item -Path $sourcePath -Destination $destinationPath -Force
# Compare files
Write-Output "Comparing files..."
$compare = fc.exe /b $sourcePath $destinationPath
if ($LASTEXITCODE -eq 0) {
Write-Output "✅ Files match: SD card passed the ${testSizeGB}GB integrity test."
} else {
Write-Output "❌ Files do NOT match: Possible fake or faulty SD card."
}
# Clean up
Write-Output "Deleting test files..."
Remove-Item $sourcePath -Force
Remove-Item $destinationPath -Force
Write-Output "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment