Skip to content

Instantly share code, notes, and snippets.

@rjhornsby
Created February 13, 2026 19:59
Show Gist options
  • Select an option

  • Save rjhornsby/14504119a6a2917131549fadf7c0ebd8 to your computer and use it in GitHub Desktop.

Select an option

Save rjhornsby/14504119a6a2917131549fadf7c0ebd8 to your computer and use it in GitHub Desktop.
list current AWS windows AMIs
#!/usr/bin/env bash
# Stupid script to find the most recent windows AMIs from Amazon
# because I'm tired of hunting for them every time.
WINDOWS_YEARS="2025 2022 2019"
function bye() {
echo "Error: $1"
exit 1
}
function get_latest_windows_ami() {
year_edition="$1"
[ -n "$year_edition" ] || bye "Missing argument for year (ie 2019, 2022, 2025)"
aws ec2 describe-images \
--owners amazon \
--filters "Name=name,Values=Windows_Server-${year_edition}-English-Full-Base*" \
--query 'sort_by(Images, &CreationDate)[].[Name, ImageId]' | jq -r '. | last | @tsv'
}
account_name="$(aws iam list-account-aliases | jq -r '.AccountAliases[0]')"
account_id="$(aws sts get-caller-identity --query 'Account' --output text)"
current_region="$(aws configure get region)"
>&2 echo "account: $account_name ($account_id) region: $current_region"
for year in $WINDOWS_YEARS; do
printf "%60s %s\n" "$(get_latest_windows_ami "$year")"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment