Skip to content

Instantly share code, notes, and snippets.

@besteban1989
Last active October 11, 2022 17:36
Show Gist options
  • Save besteban1989/cad092d17ebbea9355736a153dc21a52 to your computer and use it in GitHub Desktop.
Save besteban1989/cad092d17ebbea9355736a153dc21a52 to your computer and use it in GitHub Desktop.
Azure CLI Snippets
# List all resources on the current subscription
az resource list --query "[].[name, id, location, type, resourceGroup]" -o tsv > resources.txt
# Purge container registry and keep the last 3 tags for each repo
# Remove the --dry-run to execute the deletion
PURGE_CMD="acr purge \
--filter '.*:.*' \
--ago 0d --untagged --keep 3 --dry-run"
az acr run \
--cmd "$PURGE_CMD" \
--registry registryname \
--timeout 10600 \
/dev/null
# purge on schedule task
az acr task create --name montlyPurge \
--cmd "$PURGE_CMD" \
--schedule "0 0 1 * *" \
--registry registryname \
--timeout 10600 \
--context /dev/null
# get id from service principal when az cli doesn't find the source using the clientId/objectId.
az ad sp show --id [clientId] --query id --out tsv
# use the resultant id from the query, sounds crazy but is an id unable to be found in the Azure AD Portal -___-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment