Skip to content

Instantly share code, notes, and snippets.

@mendhak
Created October 27, 2017 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mendhak/41be93d7c2a3ae683b6ae00f9286aea7 to your computer and use it in GitHub Desktop.
Save mendhak/41be93d7c2a3ae683b6ae00f9286aea7 to your computer and use it in GitHub Desktop.
Initialize raw disks in Windows, partition, format and assign drive letters
$rawdisks = gwmi win32_diskdrive | where {$_.partitions -eq 0}
foreach ($r in $rawdisks)
{
$available=ls function:[d-z]: -n | ?{ !(test-path $_) } | SELECT -First 1
$diskIndex = $r.Index
Write-Host "Initializing Disk $diskIndex as $available. This will take a while."
(echo "list disk
select disk $diskIndex
online disk
attributes disk clear readonly
clean
create partition primary
select partition 1
active
FORMAT FS=NTFS
ASSIGN LETTER=$available
EXIT
") | diskpart
Start-Sleep -Seconds 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment