Removing user level config profiles through script pushed from JSS

bbot
Contributor

I'm trying to do something like the below. Has anyone had experience removing user level config profiles that were locally installed? I can't get it to work.

#!/bin/sh

#find current user logged in
currentuser=`stat -f "%Su" /dev/console`

profile1=`su "$currentuser" -c "/usr/bin/profiles -Lv | grep LC-802`
profile2=`echo $profile1 | awk '{print $4}'`
echo $profilename

if [[ $profile2 == "LC-802" ]]; then

    su "$currentuser" -c "/usr/bin/profiles -R -p 0F317018-2A6E-4828-8C1B-DD77B71E949B"

else

    echo profile not found

fi
1 REPLY 1

andrew_nicholas
Valued Contributor

I believe to un-install user level config profiles, you will need to have the profile somewhere on the machine locally, and pass it it in as a command line argument. The profiles man page shows the following example for -R:

profiles -R -F /profiles/testfile2.configprofile Removes the profile file '/profiles/testfile2.mobileconfig' into the current user.

Edit:
It would probably also be better to forgo the su instance and instead pass the user account into the commands. Possibly something like:

#!/bin/bash
currentuser=$(stat -f "%Su" /dev/console)

profile1=$(usr/bin/profiles -L -v -U "$currentuser" | grep LC-802 |  awk '{print $4}')
echo $profilename

if [[ "$profile1" = "LC-802" ]]; then
    /usr/bin/profiles -R -p 0F317018-2A6E-4828-8C1B-DD77B71E949B -U "$currentuser"
else
    echo "profile not found"
fi