The following works in Drupal 8 (in this example, load all users with the administrator role)
\Drupal::service('entity_type.manager') ->getStorage('user') ->loadByProperties(['roles' => 'administrator']);
will return a list of user objects.
To get the uid list instead, query the object field:
$query = \Drupal::service('entity_type.manager')->getStorage('user')->getQuery(); $query->condition('roles', 'administrator'); $query->execute();
jhedstrom
source share