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
Function Get-Device() { | |
param( | |
[parameter (mandatory=$true)][string] $InstanceId | |
) | |
$CurrentDevice = Get-EC2InstanceAttribute $InstanceId -Attribute blockDeviceMapping | Select-Object -ExpandProperty BlockDeviceMappings | Select-Object -last 1 | |
If ($CurrentDevice.DeviceName -eq '/dev/sda1') { | |
$NewDevice = 'xvdf' | |
return $NewDevice | |
} | |
Else { |
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
$server = Read-Host "Please provide the server name" | |
$InstanceId = (Get-EC2Instance | ?{$_.Instances.tag.value -like $server}).Instances.InstanceId | |
$deviceids = (Get-EC2InstanceAttribute -InstanceId $InstanceId -Attribute blockDeviceMapping | Select -ExpandProperty BlockDeviceMappings).DeviceName | |
foreach($deviceid in $deviceids) | |
{ | |
Edit-EC2InstanceAttribute -InstanceId $InstanceId -BlockDeviceMapping @{DeviceName=$deviceid;Ebs=@{DeleteOnTermination=$true}}; | |
} |