Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
Created April 6, 2019 01:01
Show Gist options
  • Select an option

  • Save MatthewJDavis/872c2cb9ba1fc0e95ce2d864c5810541 to your computer and use it in GitHub Desktop.

Select an option

Save MatthewJDavis/872c2cb9ba1fc0e95ce2d864c5810541 to your computer and use it in GitHub Desktop.
Handy ec2 commands
# Output the instance name from the tag along with a few properties
$ec2 = Get-EC2Instance
($ec2).Instances | ForEach-Object {
$properties = [ordered]@{
Name = ($_ | Select-Object -ExpandProperty tags | Where-Object -Property Key -eq Name ).value
InsanceID = $_.InstanceId
PrivateIP = $_.PrivateIpAddress
SubnetId = $_.SubnetId
InstanceType = $_.InstanceType
}
New-Object -TypeName PSObject -Property $properties
}
# Find EC2 Instance by name tag
$ec2 = Get-EC2Instance -Filter @( @{name='tag:Name' ; values="Name-*"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment