Skip to content

Instantly share code, notes, and snippets.

@wsmelton
Created September 17, 2017 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wsmelton/169aa053eb76d82bcdce21208dbc270c to your computer and use it in GitHub Desktop.
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"
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