Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
Created June 15, 2017 19:44
Show Gist options
  • Save MatthewJDavis/9618049c2b75a36b8c8ee58b7a364dfd to your computer and use it in GitHub Desktop.
Save MatthewJDavis/9618049c2b75a36b8c8ee58b7a364dfd to your computer and use it in GitHub Desktop.
Get the lastest Amazon Linux AMI
#will return the latest Amazon Linux AMI IDs using EBS for the listed regions
$regions = "eu-west-1","eu-west-2","eu-central-1"
foreach($region in $regions){
$ami = Get-EC2Image -Region $region |
Where-Object {$_.imageowneralias -eq "amazon" -and $_.virtualizationtype -eq "hvm" -and $_.name -like "*amzn-ami-hvm*" -and $_.rootdevicetype -eq "ebs"} |
Sort-Object -Property creationdate -Descending |
Select-Object -Property imageid -First 1
$output = "$region = " + $ami.ImageId
Write-Output $output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment