From 3d9e3654cca57adf67e662f02558302fed2c8363 Mon Sep 17 00:00:00 2001 From: Thrizvi <145013431+Thrizvi@users.noreply.github.com> Date: Fri, 31 Oct 2025 11:52:42 +0530 Subject: [PATCH 1/2] Create Delete Inactive user Delete Inactive Users Without Login History --- .../Delete Inactive user | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Delete Inactive Users Without Login History/Delete Inactive user 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(); + } +} From 807e0aa95e982b69324ad271bb5a2a741a276dbf Mon Sep 17 00:00:00 2001 From: Thrizvi <145013431+Thrizvi@users.noreply.github.com> Date: Fri, 31 Oct 2025 11:54:40 +0530 Subject: [PATCH 2/2] Readme.md Delete Inactive Users Without Login History --- .../Delete Inactive Users Without Login History/Readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Delete Inactive Users Without Login History/Readme.md 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