I've seen a lot of questions answered about adding EBS volumes Linux, but not Windows. Say you've discovered that your disk is running low on space (maybe via CloudWatch) and want to add another EBS volume. Can this be done with Powershell?
I'd prefer not to use diskpart.exe since it's more difficult to parse its results (not being a native Powershell command).
Hoping this helps someone out there. The AWS stuff was easy, but took me a while to track down all the things for Windows to use it.
This answer is stripped down for brevity, so make sure:
2 and 3 can be done via the Get-EC2Volume
API.
Create the EBS Volume:
$volume = New-EC2Volume -Size $sizeInGB -AvailabilityZone $az -VolumeType $vType
Attach the Volume to the EC2:
Add-EC2Volume -InstanceId $toInstanceId -VolumeId $volume.Id -Device $devId -Region $region
Windows side:
locate the ebs volume you just attached
$diskNumber = (Get-Disk | ? {
($_.OperationalStatus -eq "Offline") -and ($_."PartitionStyle" -eq "RAW") }).Number
initialize the disk
Initialize-Disk -Number $diskNumber -PartitionStyle "MBR"
create max-space partition, assign drive letter, make "active"
$part = New-Partition -DiskNumber $diskNumber -UseMaximumSize -IsActive -AssignDriveLetter
format the new drive
Format-Volume -DriveLetter $part.DriveLetter -Confirm:$FALSE
Enjoy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With