Category filter
Script to delete user account on Mac
When employees leave an organization, the corporate devices assigned to them are re-distributed to other workers in the firm. Hence, organizations may require to delete the data and user account from the devices. However, manually doing this task is a time-consuming process. IT admins can deploy scripts using Hexnode UEM’s Execute Custom Script remote action to delete user accounts and related data from macOS devices.
Scripting language – Bash
File extension – .sh
Delete the user account
1 |
sudo dscl . delete /users/<username> |
The ‘sysadminctl’ has been introduced on macOS 10.13. This command is a utility in macOS that allows administrators to perform various system administration tasks from the command line. It provides a set of commands for managing user accounts and system configurations.
1 |
sysadminctl -deleteUser <username> |
‘sysadminctl -deleteUser’ command will delete the user account from the system. This action is irreversible and will permanently remove the user account and associated home directory.
Even after the execution of the script, the user’s home folder will not be deleted. The user data will remain on the device and can be retrieved later if needed by an admin.
Delete directories and files of the user
1 |
sudo rm -rf /users/<username> |
The ‘rm’ command deletes all files and directories. By utilizing the -r and -f options, you specify whether the directories should be removed recursively and forcefully without prompting for confirmation. The user account and all associated data will be erased from the device if both commands are executed successively.