Created
September 17, 2017 22:05
-
-
Save wsmelton/169aa053eb76d82bcdce21208dbc270c to your computer and use it in GitHub Desktop.
Pull the list of EC2 instances running under your AWS account, based on using a tag called "owner"
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
param( | |
[string]$OwnerValue = 'melton', | |
[switch]$Raw | |
) | |
$myEc2Instances = Get-EC2Tag -Filter @{ Name="key"; Values="owner" },@{ Name="value";Values=$OwnerValue}, @{ Name="resource-type";Values="instance"} | |
$data = Get-EC2Instance -InstanceId $myEc2Instances.ResourceId | Select-Object -ExpandProperty Instances | |
if ($Raw) { | |
foreach ($d in $data) { | |
$value = ($d.Tags | Where-Object Key -eq Name).Value | |
Add-Member -Force -MemberType NoteProperty -Name Name -Value $value | |
} | |
return $data | |
} | |
else { | |
$data | select InstanceId, @{Label="Name";Expression={($_.Tags | where key -eq "Name").Value }}, InstanceType, PrivateIpAddress, PublicIpAddress, PublicDnsName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment