NOTE – For this script to work your instances must have a unique name tag. I use this tag for machine host-names.
This script is to identify all attached volume ID’s from a single instance Name Tag within AWS Powershell. The sections below describe the action of script sections
- Import AWS Powershell module (needs to be downloaded and installed)
- Asks for the server name from the initiator then find’s the Instance ID from the Server name
- Re-variable the instance ID
- Collect all volumes attached to the instance ID
- Select properties of the volumes and format table as auto size (make each column expand to complete text)
- Display volumes attached to instance
# 1 Add AWS cmdlets and connect
Import-Module AWSPowerShell
# 2 Server name from ID
$Server = Read-host "Server Name"
$Servertag = Get-EC2Tag -Filter @{ Name="key";Values="Name"},@{ Name="value";Values=$Server} | Where {$_.ResourceType -like '*instance*'}
$ServerId = $Servertag | % { $_.ResourceId}
# 3 Specify your instance's ID
$instance = $ServerId
# 4 Get a collection of all volumes attached to the instance
$volumes = @(get-ec2volume) | ? { $_.Attachments.InstanceId -eq $instance}
# 5 Get a collection of each volume's ID property
$volumeId = $volumes | % { $_.VolumeId}
$volumeNames = $volumes | Select VolumeId, Size, VolumeType, State, CreateTime | ft -AutoSize
# 6 Display Volume's ID
$volumeNames
This is gold !