17

I would like to list information about all users using drush.

There is user-information, but it shows information only about single user.

Are there any other solution?

5 Answers 5

14

For Drupal 8 you could run the following command:

drush uinf $(drush sqlq "SELECT GROUP_CONCAT(name) FROM users_field_data")

The output will loke something like the following:

 User ID       :  1
 User name     :  admin
 User mail     :  [email protected]
 User roles    :  authenticated
                  administrator
 User status   :  1
9

As kenorb pointed out, there is a workaround via SQL-query.

And with a minor change, it becomes more robust to special characters in names - by using "uid" (integer) instead of the user-names:

drush uinf $(drush sqlq "SELECT GROUP_CONCAT(uid) FROM users")

PS: Confirmed for Drupal 7 only.
PPS: Sorry for adding another answer, I can not comment yet.

3
  • it gives me only the 220 first users.
    – lefterav
    Sep 25, 2020 at 20:34
  • @lefterav: can you try the "SELECT" with "LIMIT x" (x being a larger number)? drush uinf $(drush sqlq "SELECT GROUP_CONCAT(uid) FROM users LIMIT 99999") PS: Currently I do not have a Drupal-installation at hand, so I can now test for myself, sorry :-(
    – El Hannes
    Dec 4, 2020 at 12:16
  • 2
    Drupal 8 & 9 syntax is: drush uinf --uid=$(drush sqlq "SELECT GROUP_CONCAT(uid) FROM users")
    – BWPanda
    Jan 5, 2022 at 3:21
7

There is recent sandbox project: Drush User List (by John) which should work for Drupal 6 & 7 (see GitHub).

Usage:

drush user-list

For other workaround, the following command with process substitution syntax should help:

drush uinf $(drush sqlq "SELECT GROUP_CONCAT(name) FROM users")

However it could fail in some cases (when users have some special characters in their name).

3

For Drupal 8, there is a Drush 9 command on Packagist, e.g.

drush users:list

List all Drupal users in a table format. See drush users:list --help for filtering options.

0

Sorry... wrote this script for Drupal 8 remote machines with aliases; easily adaptable to local if necessary.

if [ $# -lt 1 ]
then
        echo "Usage : $0 sitealias [all/disabled/enabled] [rolename]"
        echo "Note: this only runs on Drupal 8 schema"
        exit
 fi

 ARG1=$1
 ARG2=${2:-all}
 ARG3=${3:-nothing}

 if [ "$ARG3" != "nothing" ]
 then
    ROLEWHERE='AND user__roles.roles_target_id="'$ARG3'"'
 fi



 case "$ARG2" in
    enabled) 
        WHERECLAUSE='WHERE users_field_data.status="1" '$ROLEWHERE
        ;;
    disabled)
        WHERECLAUSE='WHERE users_field_data.status="0" '$ROLEWHERE
        ;;
    all)
        WHERECLAUSE='WHERE users_field_data.status LIKE "%" '$ROLEWHERE
        ;;
    *)
        WHERECLAUSE=''
        ;;
 esac

 QUERY='SELECT users_field_data.uid,users_field_data.name,users_field_data.mail,from_unixtime(users_field_data.login) AS "lastlogin",user__roles.roles_target_id,users_field_data.status FROM users_field_data LEFT JOIN user__roles ON users_field_data.uid = user__roles.entity_id '$WHERECLAUSE

 drush $1 sqlq "$QUERY"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.