Delete UIE admin users

JDK-JAMF
New Contributor

Im trying to create a script to add to policy to do a mass deletion of UIE admins left on computers but to leave the standard account and jamf installed admin accounts, put together this scrip but it doesnt work, could someone please take a look and see where im going wrong.

 

#!/bin/bash

 

adminUsers=( $(dscacheutil -q group -a name admin  | awk '/users:/ { $1=""; print $0 }' ) )

users=( $( dscl . ls /Users | grep -v '_' | grep -v 'root' | grep -v 'daemon' | grep -v 'nobody' | grep -v 'padmin' | grep -v 'aadmin'| grep -v '_padmin' | grep -v '@pcompany.com') )

 

for i in "${adminUsers[@]}"; do

for j in "${users[@]}"; do

if [[ $i == $j ]]; then

 

# delete user

/usr/bin/dscl . delete /Users/"$a" > /dev/null 2>&1

 

# delete home folder

/bin/rm -rf /Users/"$a"

continue

 

echo "Users accounts removed!"

exit 0

fi

done

done

 

0 REPLIES 0