diff --git a/Server-Side Components/Background Scripts/Delete Inactive Users Without Login History/Delete Inactive user b/Server-Side Components/Background Scripts/Delete Inactive Users Without Login History/Delete Inactive user new file mode 100644 index 0000000000..3f084a9080 --- /dev/null +++ b/Server-Side Components/Background Scripts/Delete Inactive Users Without Login History/Delete Inactive user @@ -0,0 +1,14 @@ +var gr = new GlideRecord('sys_user'); +gr.addQuery('active', false); +gr.query(); + +while (gr.next()) { + var login = new GlideRecord('syslog'); + login.addQuery('user', gr.sys_id); + login.query(); + + if (!login.hasNext()) { + gs.print('Deleting inactive user: ' + gr.name); + gr.deleteRecord(); + } +} diff --git a/Server-Side Components/Background Scripts/Delete Inactive Users Without Login History/Readme.md b/Server-Side Components/Background Scripts/Delete Inactive Users Without Login History/Readme.md new file mode 100644 index 0000000000..5f2e7f97fb --- /dev/null +++ b/Server-Side Components/Background Scripts/Delete Inactive Users Without Login History/Readme.md @@ -0,0 +1,8 @@ + +Delete Inactive Users Without Login History + +This ServiceNow background script identifies and deletes inactive users who have never logged into the system. It's useful for cleaning up unused accounts and maintaining a secure, lean user base. + +- Identify users marked as `active = false` +- Check if they have any login records in the `syslog` table +- Delete users who have no login history