Created
March 14, 2019 18:49
-
-
Save olohmann/28398736bb170cc662a49021d3fa01bd to your computer and use it in GitHub Desktop.
Quickly Clean up Azure Resource Groups in a (Demo) Subscription
This file contains hidden or 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
| #!/bin/bash | |
| GREEN='\033[0;32m' | |
| NC='\033[0m' # No Color | |
| CURRENT_SUBSCRIPTION_ID=$(az account list --all --query "[?isDefault].id | [0]" | tr -d '"') | |
| CURRENT_SUBSCRIPTION_NAME=$(az account list --all --query "[?isDefault].name | [0]" | tr -d '"') | |
| echo -e "${GREEN}[NOTE]${NC} Subscription Context: ${GREEN}${CURRENT_SUBSCRIPTION_NAME} (${CURRENT_SUBSCRIPTION_ID})${NC}" | |
| read -p "Continue to clean up RGs in this subscription (y/n)? " CONT | |
| if [ "$CONT" = "y" ]; then | |
| echo "Using ${CURRENT_SUBSCRIPTION_NAME} ($CURRENT_SUBSCRIPTION_ID)" | |
| else | |
| exit 1 | |
| fi | |
| for i in `az group list -o tsv --query [].name --subscription ${CURRENT_SUBSCRIPTION_ID}`; do | |
| if [[ "$i" =~ ^cloud-shell-storage.* ]]; then | |
| echo "Skipping $i" | |
| else | |
| echo "Deleting $i..." | |
| az group delete -n $i -y --no-wait | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment