Category filter
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.
1 2 3 4 5 6 |
if groups <username> | grep -q -w admin; then echo "Is admin"; else echo "Not admin"; fi |
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.
1 |
dscl . -read /Groups/admin GroupMembership |