Hoping this helps someone. Everything was simple, but it took me a while to track everything that was needed for Windows.
This answer has been shortened for brevity, so be sure to:
- you handled AWS Powershell API exceptions
- your volumes are “accessible” before trying to connect them to EC2
- volume shows "use" after attaching it.
2 and 3 can be done using the Get-EC2Volume .
Create an EBS volume:
$volume = New-EC2Volume -Size $sizeInGB -AvailabilityZone $az -VolumeType $vType
Connect the volume to EC2:
Add-EC2Volume -InstanceId $toInstanceId -VolumeId $volume.Id -Device $devId -Region $region
Windows side:
find the just added ebs volume
$diskNumber = (Get-Disk | ? { ($_.OperationalStatus -eq "Offline") -and ($_."PartitionStyle" -eq "RAW") }).Number
initialize disk
Initialize-Disk -Number $diskNumber -PartitionStyle "MBR"
create a max-space partition, assign a drive letter, make it "active"
$part = New-Partition -DiskNumber $diskNumber -UseMaximumSize -IsActive -AssignDriveLetter
format new drive
Format-Volume -DriveLetter $part.DriveLetter -Confirm:$FALSE
Enjoy it!
source share