Skip to main content
Question

Remove all OSX profiles through command line

  • March 21, 2016
  • 7 replies
  • 37 views

Forum|alt.badge.img+3

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

bpavlov
Forum|alt.badge.img+18
  • Esteemed Contributor
  • March 21, 2016

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

Forum|alt.badge.img+3
  • Author
  • New Contributor
  • March 21, 2016

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


Forum|alt.badge.img+12
  • Valued Contributor
  • March 21, 2016

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


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • March 21, 2016

Yes it will remove them, despite the error notice.


Forum|alt.badge.img+7
  • Contributor
  • March 21, 2016

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
Forum|alt.badge.img+18
  • Esteemed Contributor
  • March 21, 2016

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

#!/bin/sh

Forum|alt.badge.img+19
  • Contributor
  • May 12, 2018
#!/bin/sh
profiles remove -forced -all