List the sys_id of all Group Records in ServiceNow

It is difficult to get a report with sys_id listed in ServiceNow. I had an issue where some of our Group records between instances had differing sys_ids. To audit the records between instances, I used the following background script to quickly get a list of Groups with Group Name, sys_id, and whether or not the group was Active. I formatted the output as a CSV file so Excel can open it.

You can use this same technique to get the sys_id of any record type in ServiceNow.

var group_gr = new GlideRecord("sys_user_group");
var csvString = '"Name","sys_id","Active"\n';
group_gr.query();
while (group_gr.next()) {
    csvString += '"' + group_gr.name + '","' + group_gr.sys_id + '","' + group_gr.active + '"\n';
}
gs.log(csvString);