Remove all OSX profiles through command line

danielslijper
New Contributor

Hi,

I was looking for a way to remove all profiles of the previous MDM server via command line / script but didn't find one so I wrote one and thought i'd share...

#!/bin/bash

# Get a list from all profiles installed on the computer and remove every one of them

for identifier in $(profiles -L | awk "/attribute/" | awk '{print $4}')
do profiles -R -p $identifier
done

After this you can do sudo jamf manage mdm to get all the right profiles installed....

7 REPLIES 7

bpavlov
Honored Contributor

Are the profiles installed by the JSS? If so, this should take care of it too. For whatever reason it's not documented.

sudo jamf removemdmprofile

danielslijper
New Contributor

Unfortunately, it was another MDM solution so that option would not help there. Thanks for sharing though.

SGill
Contributor III

Have you seen whether this script can remove a profile that has the "remove-never" flag set in the General payload section under Security?

danielslijper
New Contributor

Yes it will remove them, despite the error notice.

chad_fox
Contributor II

I've been using the one below that I found searching around here:

!/bin/bash

Get UUID of requested MDM Profile

MDMUUID=profiles -Lv | grep "name: $4" -4 | awk -F": " '/attribute: profileIdentifier/{print $NF}'

Remove said profile, identified by UUID

if [[ $MDMUUID ]]; then profiles -R -p $MDMUUID
else echo "No Profile Found"
fi

sleep 5

I have a policy for each MDM profile installed by our previous management suite. Had good luck so far.

bpavlov
Honored Contributor

When attaching a script be sure to use the >_ button and paste the script inside the quotes so that it preserves formatting.

#!/bin/sh

nkalister
Valued Contributor
#!/bin/sh
profiles remove -forced -all