Created
October 27, 2017 13:27
-
-
Save mendhak/41be93d7c2a3ae683b6ae00f9286aea7 to your computer and use it in GitHub Desktop.
Initialize raw disks in Windows, partition, format and assign drive letters
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
$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