Skip to content

Instantly share code, notes, and snippets.

@lantrix
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save lantrix/bb0fea3b029dcbd1ca9c to your computer and use it in GitHub Desktop.

Select an option

Save lantrix/bb0fea3b029dcbd1ca9c to your computer and use it in GitHub Desktop.
Stripe AWS Ephemeral Drive where 2 x available
#
# This will take the two non-system disks on an AWS windows server 2012 R2 instance and ERASE THEM; creating a single striped Volume.
# WARNING: Before using this be sure to check that ((Get-Disk) |where issystem -eq $false) are actually the ***DISKS YOU WANT ERASED***
#
#Get ephemeral disk
$ephemeralDisks = (Get-Disk) |where issystem -eq $false
if ($ephemeralDisks.Count -ne 2) {throw "Not correct amount of disks. Expecting 2"}
#Prepare diskpart Script for each disk
foreach ($disk in $ephemeralDisks) {
$clean = "select disk $($disk.Number)"+[char][int](13)+[char][int](10); #Select Disk
$clean += "clean"+[char][int](13)+[char][int](10); #Clear Disk
$clean += "attributes disk clear readonly noerr "+[char][int](13)+[char][int](10); #set attributes
$clean += "convert dynamic noerr "+[char][int](13)+[char][int](10); #convert to dynamic
$clean += "exit"+[char][int](13)+[char][int](10);
$clean | Set-Content c:\diskpartA_$($disk.Number).txt -Encoding ASCII
}
#Execute script for each disk
foreach ($disk in $ephemeralDisks) {
& Diskpart /s c:\diskpartA_$($disk.Number).txt
Remove-Item c:\diskpartA_$($disk.Number).txt
}
#Prepare striped Ephemeral Volume
$striped = "create volume stripe disk="
foreach ($disk in $ephemeralDisks) {
#join volumes together for strip set
$striped = $striped + $disk.Number + ","
}
$striped = $striped -replace ".$" #remove last ,
$striped = $striped +[char][int](13)+[char][int](10); #add CR/LF
$striped += "format fs=NTFS unit=4096 label=`"Temporary Storage`" quick "+[char][int](13)+[char][int](10); #Format Vol
$striped += "assign letter=Z "+[char][int](13)+[char][int](10); #Assign Drive Letter
$striped += "exit"+[char][int](13)+[char][int](10);
$striped | Set-Content c:\diskpartB.txt -Encoding ASCII
#Execute striped Volume
& Diskpart /s c:\diskpartB.txt
Remove-Item c:\diskpartB.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment