Last active
May 30, 2022 16:18
-
-
Save caseywatson/04495f049b4e6e1166544476db69bf7c to your computer and use it in GitHub Desktop.
Simple script for quickly and safely deleting AAD app registrations that you own.
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 -e | |
delete_aad_app() { | |
az ad app delete --id "$1" | |
echo "AAD app [$1] deleted." | |
} | |
usage() { | |
echo "Usage: $0 [-y]" | |
} | |
while getopts "y" opt; do | |
case $opt in | |
y) | |
yes=1 | |
;; | |
\?) | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
while [[ -z $current_user_oid ]]; do | |
current_user_oid=$(az ad signed-in-user show --query id --output tsv 2>/dev/null); | |
if [[ -z $current_user_oid ]]; then az login; fi; | |
done | |
my_aad_app_ids=$(az ad app list --output tsv --query '[].appId' --show-mine) | |
for my_aad_app_id in $my_aad_app_ids; do | |
if [[ -n $yes ]]; then | |
delete_aad_app "$my_aad_app_id" | |
else | |
my_aad_app_name=$(az ad app show --id "$my_aad_app_id" --output tsv --query 'displayName') | |
read -r -p "Delete [$my_aad_app_name ($my_aad_app_id)]? [Y/n] " yn | |
case $yn in | |
[1Yy]) | |
delete_aad_app "$my_aad_app_id" | |
;; | |
esac | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment