AWS Volume ID from Instance Name Tag

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

  1. Import AWS Powershell module (needs to be downloaded and installed)
  2. Asks for the server name from the initiator then find’s the Instance ID from the Server name
  3. Re-variable the instance ID
  4. Collect all volumes attached to the instance ID
  5. Select properties of the volumes and format table as auto size (make each column expand to complete text)
  6. 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


1 comment

    • Steven on April 25, 2017 at 9:06 pm


    This is gold !

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.