Enhanced macOS User Account Details Bash Script

This Bash script retrieves and displays detailed information for all human user accounts (UID ≥ 500) on macOS, including the username, UID, admin privileges, full name, home directory, and default shell. It provides a clear and organized summary that is useful for system administrators to review and manage user configurations.

Click to view script…
#!/bin/bash
# This script lists user accounts (UID >= 500) and shows additional details:
# Username, UID, Admin Privileges (true/false), Full Name, Home Directory, and Shell

# Print header for clarity
echo "Username : UID : Has Admin Privileges : Full Name : Home Directory : Shell"

# List all users with their UniqueID and process each line
dscl . -list /Users UniqueID | while read username uid; do
    # Only process accounts with UID >= 500 (typically non-system, human user accounts)
    if [ "$uid" -ge 500 ]; then
        # Check if the user belongs to the 'admin' group
        if id -Gn "$username" 2>/dev/null | grep -qw "admin"; then
            adminFlag="true"
        else
            adminFlag="false"
        fi

        # Get the user's full name (if set). The command outputs a line like "RealName: John Doe"
        fullName=$(dscl . -read /Users/"$username" RealName 2>/dev/null | sed 's/RealName: //')
        
        # Get the user's home directory
        homeDir=$(dscl . -read /Users/"$username" NFSHomeDirectory 2>/dev/null | sed 's/NFSHomeDirectory: //')
        
        # Get the user's default shell
        shell=$(dscl . -read /Users/"$username" UserShell 2>/dev/null | sed 's/UserShell: //')
        
        # Output the collected information in a clear, colon-separated format
        echo "$username : $uid : $adminFlag : $fullName : $homeDir : $shell"
    fi
done