-
Notifications
You must be signed in to change notification settings - Fork 29
/
cleanappsp.sh
executable file
·32 lines (24 loc) · 1.36 KB
/
cleanappsp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# Written by Stuart Kirk
# stuart.kirk@microsoft.com
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Erases all Azure AD Apps and Service Principals that start with "aro-".
# This is useful when clusters are stood up / torn down with frequency to keep AAD clean.
# Note: This script will delete *all* Azure AD Apps and Service Principals, without confirmation, with the "aro-" prefix. All others will remain.
for i in `az ad app list --show-mine -o json | jq -r ".[] | .displayName" |grep "aro-"`; do az ad app list --display-name $i -o json | jq -r ".[] | .objectId"; done > appids
for i in `cat appids`; do
echo "Erasing appid: $i"
az ad app delete --id $i
done
for j in `az ad sp list --show-mine -o json | jq -r ".[] | .displayName" |grep "aro-"`; do az ad sp list --display-name $i -o json | jq -r ".[] | .objectId"; done > spids
for j in `cat spids`; do
echo "Erasing sp: $j"
az ad sp delete --id $j
done
rm -f appids
rm -f spids