get_role_users() takes the paramater $sort. According to the comments above this function it can be used to "sort from user (u.) , role assignment (ra) or role (r.)". But when running Moodle on Microsoft SQL it is possible to generate an SQL error when sorting by a field which is not within the user table. The following was generated when using "ra.timemodified" as $sort:
"Debug info: ORDER BY items must appear in the select list if SELECT DISTINCT is specified."