How To Export Associated Groups & Roles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 08:42 AM
I'm trying to obtain an excel spread sheet of all the groups, child groups, and their associated/inherited roles. Is there a way to export some file showing these relationships?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 11:17 PM
If you're admin, go to System Security > Users and Groups > Groups, run a filter to select the desired groups, and right click the column header to export to xlsx, csv, etc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 04:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 04:33 PM
Go to System Security > Groups Roles. All roles are listed. Right-click on the context menu at top of column and Group By Group if you wish. Run a filter search, right click header at top, and export to xlsx, csv, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2023 01:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 05:16 PM
Hello @MrDevanWright,
You could achieve this using a script. While probably not the most efficient way, it should work. The script below creates an array of group objects with the information you are asking for. You could then export to a csv using an adaptation of the script at this link.
function getRoles(groupSysId){
// Create empty array of roles
var roles = [];
// Query all roles assigned to group
var groupHasRoleQuery = new GlideRecord('sys_group_has_role');
groupHasRoleQuery.addQuery('group', groupSysId);
groupHasRoleQuery.query();
// For each role
while (groupHasRoleQuery.next()){
// Create role object with name and sys_id of role
var role = {'name': groupHasRoleQuery.role.name,'sys_id': groupHasRoleQuery.role.sys_id}
// Add role object to array of roles
roles.push(role);
}
// Return array of roles
return roles;
}
// Create empty array of groups
var groups = [];
// Query all top-level groups
var groupQuery = new GlideRecord('sys_user_group');
groupQuery.addQuery('parent','');
groupQuery.query();
// For each group
while (groupQuery.next()){
// Create group object
var group = {};
// Add group name
group.name = groupQuery.name;
// Add group sys_id
group.sys_id = groupQuery.sys_id;
// Add array of roles associated with group
groups.roles = getRoles(groupQuery.sys_id);
// Create empty array of children
group.children = [];
// Query all children groups of the group
var childrenGroups = new GlideRecord('sys_user_group');
childrenGroups.addQuery('parent', groupQuery.sys_id);
childrenGroups.query();
// For each child group
while (childrenGroups.next()){
// Create a child object with the name, sys_id, and array of roles associated with the child group
var child = {'name':childrenGroups.name,'sys_id':childrenGroups.sys_id,'roles':getRoles(childrenGroups.sys_id)};
// Add child to array of children
group.children.push(child);
}
// Add group to array of groups
groups.push(group);
}