diff --git a/Core ServiceNow APIs/GlideRecord/find inactive users in user table/ListofUserRecords.js b/Core ServiceNow APIs/GlideRecord/find inactive users in user table/ListofUserRecords.js new file mode 100644 index 0000000000..dc55fb99bb --- /dev/null +++ b/Core ServiceNow APIs/GlideRecord/find inactive users in user table/ListofUserRecords.js @@ -0,0 +1,17 @@ +// This script finds users who are inactive or haven't logged in for 90+ days + +var today = new GlideDateTime(); +var ninetyDaysAgo = new GlideDateTime(); +ninetyDaysAgo.addDaysUTC(-90); + +var gr = new GlideRecord('sys_user'); +gr.addQuery('active', false); // user is inactive +gr.addOrCondition('last_login_time', '<', ninetyDaysAgo); // or last login before 90 days ago +gr.query(); + +var oldUsers = []; +while (gr.next()) { + oldUsers.push(gr.getValue('name')); +} + +gs.info('Inactive or old users: ' + oldUsers.join(', ')); diff --git a/Core ServiceNow APIs/GlideRecord/find inactive users in user table/README.md b/Core ServiceNow APIs/GlideRecord/find inactive users in user table/README.md new file mode 100644 index 0000000000..941ab42a39 --- /dev/null +++ b/Core ServiceNow APIs/GlideRecord/find inactive users in user table/README.md @@ -0,0 +1 @@ +This script finds users who are inactive in the sys_user table who have not logged in for over 90 days