AWS – Use PowerShell to list VPC and Instance information in one view

One thing I am missing in the Amazon Web Services interface/dashboard is the ability to see information from both the VPC and the instance in one screen.
For example: I want the name of the vpc, the vpc id, the name of the instance, the instance id, the state of the vpc and the name of the keypair it’s using.
For this, I’ve written the following small script, just to get a quick overview:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

$Instances=(Get-EC2Instance).instances

$VPCS=Get-EC2Vpc

foreach($VPC in$VPCS){

$Instances|Where-Object{$_.VpcId-eq$VPC.VpcId}|foreach{

New-Object-TypeNamePSObject-Property@{

'VpcId'=$_.VpcId

'VPCName'=($VPC.Tags|Where-Object{$_.Key-eq'Name'}).Value

'InstanceId'=$_.InstanceId

'InstanceName'=($_.Tags|Where-Object{$_.Key-eq'Name'}).Value

'LaunchTime'=$_.LaunchTime

'State'=$_.State.Name

'KeyName'=$_.KeyName

}

}

}

Note: A next step could be that you can turn this into a function and pipe this function to Out-GridView 🙂