I think I might have potentially find out how to do it, though I haven't fully tested it with other activities yet:
$modinfo = \get_fast_modinfo($course);
$cm = $modinfo->get_cm($courseModule->id);
$info = new \core_availability\info_module($cm);
$users = $info->filter_user_list( $students );