Introduction
You think deleting files is enough. You think formatting a drive makes it clean. It doesn’t. The data lingers. In slack space. In metadata. In fragments your OS pretends don’t exist.
You’ve got an external hard drive. It’s corrupted, maybe dying. Maybe it’s just old. But it still holds everything—your code, your logs, your personal archive. And if you throw it out like that, someone else owns it now.
This isn’t about paranoia. It’s about control. You don’t let the system decide when your data dies. You do.
This PowerShell script doesn’t ask questions. It maps the volume, verifies the physical disk, prompts you once, and then wipes every sector. No GUI. No third-party tools. Just raw commands and a log file to prove it happened.
Walkthrough: Securely Wipe an External HDD with PowerShell
Step 1: Create the Script
Add this code to a .txt
file and place the file on your Desktop:
# WipeExternalDisk.ps1
# Securely wipes the physical disk hosting volume E: and logs the process
$volumeLetter = "E"
$logPath = "$env:USERPROFILE\Desktop\DiskWipeLog_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt"
function Log($msg) {
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"$timestamp - $msg" | Out-File -Append $logPath
Write-Host $msg
}
Log "=== Disk Wipe Started ==="
# Get volume info
$vol = Get-Volume -DriveLetter $volumeLetter
if (-not $vol) {
Log "ERROR: Volume $volumeLetter not found."
exit
}
Log "Volume $volumeLetter found: $($vol.FriendlyName), Size: $([math]::Round($vol.Size/1GB,2)) GB"
# Get associated partition and disk
$partition = Get-Partition -DriveLetter $volumeLetter
$disk = Get-Disk -Number $partition.DiskNumber
Log "Mapped to Disk $($disk.Number): $($disk.FriendlyName), Size: $([math]::Round($disk.Size/1GB,2)) GB"
# Confirm wipe
$confirm = Read-Host "Type YES to wipe Disk $($disk.Number) hosting volume $volumeLetter"
if ($confirm -ne "YES") {
Log "Wipe aborted by user."
exit
}
# Generate diskpart script
$scriptPath = "$env:TEMP\diskpart_wipe.txt"
@"
select disk $($disk.Number)
clean all
"@ | Set-Content $scriptPath
Log "Executing diskpart wipe..."
Start-Process diskpart -ArgumentList "/s `"$scriptPath`"" -Wait -NoNewWindow
Log "Diskpart wipe completed."
Log "=== Disk Wipe Finished ==="
Write-Host "Log saved to: $logPath"
Note: The drive letter
E
in the code correlates to the external hard disk’s volume. Modify it if needed.
Step 2: Execute the Script
- Save the file as
WipeExternalDisk.ps1
- Press
Ctrl + X
→ Select Windows PowerShell (Admin) - Run the following commands:
cd ~/Desktop
.\WipeExternalDisk.ps1
- When prompted, type:
YES
Step 3: Confirm the Wipe
A confirmation .txt
file will appear on your Desktop. It logs:
- Volume identity
- Disk mapping
- Confirmation timestamp
- Wipe completion status
If the drive now shows as Unallocated in Disk Management, the wipe succeeded.
Final Thoughts
This script doesn’t just delete—it erases. It doesn’t just clean—it kills. If you’re disposing of a drive, do it right. Leave no trace. Leave no recovery path. Leave no doubt.
Because the only thing worse than losing control of your data… is thinking you still have it.
Top comments (0)