Script to check if a user is an administrator on Mac
A macOS device may have multiple user accounts with administrator privileges. You can list these accounts with admin access and remotely check if a particular user has admin access by executing scripts using Hexnode’s Execute Custom Script action.
Scripting language – Bash
File extension – .sh
Check if a user is admin or not
The command returns “is admin” or “not admin” based on the username provided. Pass the username of the account to the device by replacing
username in the script.
if groups <username> | grep -q -w admin;
echo "Is admin";
echo "Not admin";
groups: shows all username groups
grep –q –w admin: searches for username user in the ‘admin’ group
Fetch a list of admin users
The command reads and lists all users with admin privileges.
dscl . -read /Groups/admin GroupMembership