Advanced Drupal User Management With Drush
Using Drupal’s built-in user interface is great for site managers and is easy to use. But if you’re a drupal developer, you might want to leverage the power of Drush.
For those that don’t know, Drush is a shell interface that allows you to work with drupal via the command line. It allows you to perform tasks quickly using a few small commands rather than clicking away with drupals UI.
Here are a few code snippets to get you started with managing users with Drush:
Create a New Drupal User
To create a new drupal user, use the following command:
This command creates a new user with the username “newuser” and fills out the password and email address fields.
List Drupal User Information
To view user information, you would use the following command. This command accepts the user name, id or email address.
drush user-information newuser
Block Drupal Users:
Lets face it, not every user is nice. So if you have a fake account or a crazy user, here is how you confront crazy user.
drush user-block crazyuser
This command will block the user with username “crazyuser.” We can also use a comma separated list of user names, ID’s or email address like so:
drush user-block --uid=2,5 --name=newuser,crazyuser --email@example.com,firstname.lastname@example.org
Add Drupal Role
Just like adding a role using drupals UI, we can do it in drush with the following command:
drush user-add-role "administrator" newuser
Reset User Passwords:
Who can remember all those darn passwords anyway? This command has saved me a few times in the past and will comes in handy:
drush user-password newuser --password="newpassword"
Check out my other blog post for a simple overview of drupal user manament.