Skip to content

Instantly share code, notes, and snippets.

@kellyebler
Last active September 17, 2019 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellyebler/8e45697c1dbe10813f72ac0d430b1121 to your computer and use it in GitHub Desktop.
Save kellyebler/8e45697c1dbe10813f72ac0d430b1121 to your computer and use it in GitHub Desktop.
Finds out if we're enrolled in SimpleMDM and removes any profiles that are not installed by SimpleMDM if so.
#!/bin/bash
## find out if we're enrolled in SimpleMDM
mdmstatus=`/usr/bin/profiles status -type enrollment | grep MDM | /usr/bin/awk '{ print $3 }'`
if [ mdmstatus='Yes' ]
then
# Get a list of all profiles on computer that aren't 'unwiredmdm' and remove all of them
echo "MDM status is Yes. Removing profiles that aren't enforced by SimpleMDM"
for identifier in $(/usr/bin/profiles -L | grep -v unwiredmdm | /usr/bin/awk "/attribute/" | /usr/bin/awk '{print $4}')
do /usr/bin/profiles -R -p $identifier
done
exit 0
else
echo "User not enrolled in MDM. Not touching profiles."
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment