Completely wipe a hard drive with PowerShell! We have to do this from time to time and I thought it would be nice to use a simple utility I wrote myself. Hammers work too and are way faster.
Do you plan on pitching an old hard drive? Are you selling an old computer with the harddrive? Be sure to wipe the hard drive(s) first so no sensitive data gets in the wrong hands. I doubt 99% of the people that would aquire an old drive would go through the trouble to see what’s left on it, but you never know.
This script will make a drive unrecoverable and unreadable. It can also make it ready for the next user.
All I ask is to please be super careful as a simple mistake could wipe a drive you do not want to wipe. The evil parts are commented out so if you want to use it, and not check it out, uncomment those marked lines.
# If not installed.
##Get-Command -Module Storage
<#
Disk Wiper 2025. Kills disks dead!
Author: C. Nichols 2025
Connect disk, mount, review, kill!
Or simply run away like a roach in a lighted kitchen.
#>
<#
>>>----------------------------------------------------------------------
**** FUNCTIONS ****
------------------------------------------------------------------------>
#>
function Wipe-Disk() {
PARAM (
$DiskNumber,
$WriteCount = 3,
$Confirm = $false
)
# Remove all partitions on the disk.
Get-Partition -DiskNumber $DiskNumber | ForEach-Object {
try {
# Commented for safety.
<# #Remove-Partition -DiskNumber 1 -PartitionNumber 1 -Confirm:$Confirm -ErrorAction Stop #>
Write-Host "removed partition $_.PartitionNumber on disk $DiskNumber" -ForegroundColor Green
} catch {
Write-Host "failed to remove partition $_.PartitionNumber on disk $DiskNumber" -ForegroundColor Red
}
}
foreach ($i in 1..$WriteCount) {
try {
# Commented for safety.
<# #Clear-Disk -Number $DiskNumber -RemoveData -Confirm:$Confirm -ErrorAction Stop #>
Write-Host "Wrote to $_.PartitionNumber on disk $DiskNumber, pass $i" -ForegroundColor Green
} catch {
Write-Host "Failed to write to $_.PartitionNumber on disk $DiskNumber, pass $i" -ForegroundColor Red
}
}
}
function Set-NewPartition() {
PARAM (
$DiskNumber,
$DriveLetter,
$Label = ""
)
try {
# Commented for safety.
<# #New-Partition -DiskNumber $DiskNumber -UseMaximumSize -DriveLetter $DriveLetter -ErrorAction Stop #>
Write-Host "Disk $DiskNumber partitioned successfully as $DriveLetter" -ForegroundColor Green
# Commented for safety.
<# #Format-Volume -DriveLetter $DriveLetter -FileSystem NTFS -NewFileSystemLabel $Label -FullFormat -ErrorAction Stop #>
Write-Host "Disk $DriveLetter formatted successfully." -ForegroundColor Green
} catch {
Write-Host "Disk $DriveLetter failed partitioning." -ForegroundColor Red
}
}
<#
>>>----------------------------------------------------------------------
**** MAIN PROGRAM ****
------------------------------------------------------------------------>
#>
# Get the disk number, partitions, and related info.
Write-Host "If the drive is not available connect/mount disk, then restart this process."
Get-Partition | Format-Table -Property DiskNumber, DriveLetter, PartitionNumber, Size, IsSystem, IsBoot, Type, DiskID -AutoSize -Wrap
Write-Host "WARNING: This program removes partitions and wipes drives completely! Select wisely as affected data contained on disk will no longer be recoverable.`n" -ForegroundColor Red
Write-Host "Press 'Esc' to exit." -ForegroundColor Cyan
do {
$key = [System.Console]::ReadKey($true)
$DiskNumber = Read-Host -Prompt "Wipe disk: enter disk number"
$FinalWarning = Read-Host -Prompt "Proceed with disk wipe, y/n"
if ($FinalWarning.ToLower().Trim() -eq "y" -or $FinalWarning.ToLower().Trim() -eq "yes") {
$disknumber = Read-Host -Prompt "Enter disk number"
$writecount = Read-Host -Prompt "How many writes? [default = 3]"
$confirm = Read-Host -Prompt "Confirm [default = false]"
if ($writecount.Trim().Length -eq 0) {
$writecount = 3
}
if ($confirm.Trim().Length -eq 0) {
$confirm = $false
} else {
$confirm = $true
}
Wipe-Disk -DiskNumber $disknumber -WriteCount $writecount -Confirm $confirm
$DoPartition = Read-Host -Prompt "Partition and format drive for reuse, y/n"
if ($DoPartition.ToLower().Trim() -eq "y" -or $DoPartition.ToLower().Trim() -eq "yes") {
$driveletter = Read-Host -Prompt "Assign drive letter that is not in use"
$label = Read-Host -Prompt "Label"
Set-NewPartition -DiskNumber $disknumber -DriveLetter $driveletter -Label $label
}
Write-Host "All processes completed.`nExiting" -ForegroundColor Cyan
Exit 0
}
} while ($key.Key -ne 'Escape') # Exit the loop when 'Esc' is pressed