Created
June 15, 2017 19:44
-
-
Save MatthewJDavis/9618049c2b75a36b8c8ee58b7a364dfd to your computer and use it in GitHub Desktop.
Get the lastest Amazon Linux AMI
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
#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