Create Windows Spanned Volume

The following PowerShell script finds the AWS ephemeral drives and creates a spanned volume, attached as the Z: drive. I used this in a bootstrap script to dynamically allocate processing space.


$disks = (wmic diskdrive list brief | measure-object -line | select -ExpandProperty Lines)-2

1..$disks | ForEach-Object -Begin {$a = $null} -Process { $a += $("select disk "+$_+[char][int](13)+[char][int](10)) ; $a += "online disk noerr "+[char][int](13)+[char][int](10) ; $a += "clean "+[char][int](13)+[char][int](10) ; $a += "attributes disk clear readonly noerr "+[char][int](13)+[char][int](10) ; $a += "convert dynamic noerr "+[char][int](13)+[char][int](10) ;} -End { $a += "exit"+[char][int](13)+[char][int](10) ;  $a | Set-Content c:\diskpart1.txt -Encoding ASCII }

$a = "create volume stripe disk=1"
2..$disks | ForEach-Object -Process {$a += ","+$_}
$a += [char][int](13)+[char][int](10)
$a += "format fs=ntfs label=scratch quick"+[char][int](13)+[char][int](10)
$a += "assign letter=z"+[char][int](13)+[char][int](10)
$a += "exit"+[char][int](13)+[char][int](10)

$a | Set-Content c:\diskpart2.txt -Encoding ASCII

Diskpart /s c:\diskpart1.txt
Diskpart /s c:\diskpart2.txt

https://gist.github.com/nsabine/6177413


comments powered by Disqus