# 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](https://www.hexnode.com/mobile-device-management/help/how-to-run-scripts-on-mac-using-hexnode-mdm/) action.

Scripting language – Bash

File extension – .sh

 Disclaimer:The sample scripts provided below are adapted from third-party open-source sites.

 

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.

Script to check if user is admin

if groups <username> | grep -q -w admin; then echo "Is admin"; else echo "Not admin"; fi

   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.

script to fetch list of admin users

dscl . -read /Groups/admin GroupMembership

   1

  dscl . -read /Groups/admin GroupMembership

   

 

  

 Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.