Created
December 2, 2016 19:27
-
-
Save b-/40efeebc4813667c6400b56aedf70fd6 to your computer and use it in GitHub Desktop.
Wipe "USB 3.0*" disks in PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ## ### ######## ## ## #### ## ## ###### | |
## ## ## ## ## ## ## ### ## ## ### ## ## ## | |
## ## ## ## ## ## ## #### ## ## #### ## ## | |
## ## ## ## ## ######## ## ## ## ## ## ## ## ## #### | |
## ## ## ######### ## ## ## #### ## ## #### ## ## | |
## ## ## ## ## ## ## ## ### ## ## ### ## ## | |
### ### ## ## ## ## ## ## #### ## ## ###### | |
# This script WILL unrecoverably erase any drives that meet the criteria directly below. | |
# It will not ask for permission. | |
# It's probably a bad idea. | |
# Don't run this. | |
$diskname = @{ Property = "FriendlyName" | |
Like = $true | |
Value = "USB 3.0*" } | |
$clearoptions = @{ RemoveData = $true | |
RemoveOEM = $true | |
Confirm = $false } # danger! | |
$initoptions = @{ PartitionStyle = "MBR" } | |
$partoptions = @{ DriveLetter = "Z" | |
UseMaximumSize = $true } | |
$sn = "" | |
Remove-Variable -Name "sn" -Force -Confirm:$false | |
while ($true) { | |
$diskarray = @(get-disk | Where-Object @diskname) | |
if (($diskarray.Count -ge 1) -and ($diskarray[0].SerialNumber -ne $sn)) { # if there is a disk and its serial number is not equal to the last wiped disk's serial number | |
$sn = $diskarray[0].SerialNumber # set "sn" variable to its serial number | |
$diskarray[0] | # take that disk... | |
Clear-Disk @clearoptions -PassThru | # erase it, passing it through the pipeline | |
Initialize-Disk @initoptions -PassThru | # initialize it, passing it through the pipeline | |
New-Partition @partoptions # partition it. | |
& format z: /p:1 /y | Get-Unique # format the disk, zeroing it out once, without prompting for confirmation. Pipe the output to Get-Unique to fix a powershell bug | |
} | |
else { | |
Write-Output "Waiting 5 seconds for the disk to change..." | |
Start-Sleep -Seconds 5 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment