Posted on 04-14-2015 07:19 PM
Hi all,
Is there a way within Casper to remove all local user profiles except for the local admin account?
Was wanting to do this using a Policy or Configuration Profile
Much appreciated
Posted on 04-14-2015 11:22 PM
Do you mean the user home folders in /Users? If so you can use something like this:
counter=`ls /Users | grep -v -E ‘grep -v ‘Shared|Guest|.localized|.DS_Store|localadmin’ | grep “[A-z 0-9]” | grep -c "[A-z 0-9]"`
# Outputs the number of folders in the /Users directory, excluding the Shared, Guest and localadmin directories and the .ds_store file.
# Loop start
while [ $counter -ne 0 ]
do
targetFolder=`ls /Users | grep -v -E ‘grep -v ‘Shared|Guest|.localized|.DS_Store|localadmin’ | grep “[A-z 0-9]” | head -$counter | tail -1`
# Gets the target folder name
# Action to take on target folder $targetFolder
# Deletes the target folder
counter=$(( $counter - 1 ))
# Reduces the counter by 1
done
exit 0
On the line "# Action to take on target folder $targetFolder", you would add in something like "rm -rf $targetFolder".
I've intentionally left that bit out, incase anyone grabs this script in the future without reading it ;).
Posted on 04-15-2015 05:41 AM
We use the the script referenced here. https://jamfnation.jamfsoftware.com/discussion.html?id=4502
May need to modify it based on what UID your local admin account has.
Posted on 04-16-2015 07:18 PM
@davidacland Exactly what I meant however I'm getting this message where I run it.
I've slightly modified the code to exclude only the 'Shared' folder.
counter=ls /Users | grep -v -E ‘grep -v ‘Shared’ | grep “[A-z 0-9]” | grep -c "[A-z 0-9]"
while [ $counter -ne 0 ]
do
targetFolder=ls /Users | grep -v -E ‘grep -v ‘Shared’ | grep “[A-z 0-9]” | head -$counter | tail -1
rm -rf $targetFolder
counter=$(( $counter - 1 )) done
Running script Delete Local User Profiles... Script exit code: 0 Script result: grep: ‘Shared’: No such file or directory grep: brackets ([ ]) not balanced Submitting log to https://server.local:8443/ Finished.
Posted on 04-17-2015 01:21 AM
Here's what you need:
counter=`ls /Users | grep -v Shared | grep "[A-z 0-9]" | grep -c "[A-z 0-9]"`
while [ $counter -ne 0 ]
do
targetFolder=`ls /Users | grep -v Shared | grep "[A-z 0-9]" | head -$counter | tail -1`
rm -rf /Users/$targetFolder
counter=$(( $counter - 1 ))
done
exit 0