From 576046703726c760b218128c4ba6d7df759e162d Mon Sep 17 00:00:00 2001 From: Abhishek Thakur <146176327+at8807602@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:04:25 +0530 Subject: [PATCH 1/5] Create Disable Service accounts due to inactivity This schedule job script will help to auto disable the service accounts which has not been logged in or used for last 40 days. --- ...Disable Service accounts due to inactivity | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity diff --git a/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity b/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity new file mode 100644 index 0000000000..f352cb5432 --- /dev/null +++ b/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity @@ -0,0 +1,19 @@ +var user = new GlideRecord("sys_user"); // Glide to user table +user.addActiveQuery(); +user.addEncodedQuery("u_service_account=true"); // Adding encoded query to filter the only Service Account +user.query(); +while (user.next()) { + var arr = []; // Definind an empty array + arr.push(user.user_name); // pushing all he usernames with in the array + for (var i = 0; i <= arr.length - 1; i++) { + var userID = arr[i]; + var query1 = "sys_created_onRELATIVELT@dayofweek@ahead@40^sys_created_by=" + userID; // creating a dynamic query to check if the account has any transaction in last 40 days on transaction table. + var tranSaction = new GlideRecord("syslog_transaction"); // Glide to the tranaction table + tranSaction.addEncodedQuery(query1); // adding an query1 + tranSaction.query(); + tranSaction.orderByDesc("sys_created_on"); + if (!tranSaction.next()) { + gs.print(arr); // this will print only user names which does not have any transaction in last 40 days on log transaction table. + } + } +} From c97b0e5110bebf7c2db902f99ab8c4f5f32b9247 Mon Sep 17 00:00:00 2001 From: Abhishek Thakur <146176327+at8807602@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:07:33 +0530 Subject: [PATCH 2/5] Create Readme.md This file gives the information about the above file for auto disabling the service accounts --- .../Scheduled Jobs/Auto Disable account/Readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Server-Side Components/Scheduled Jobs/Auto Disable account/Readme.md diff --git a/Server-Side Components/Scheduled Jobs/Auto Disable account/Readme.md b/Server-Side Components/Scheduled Jobs/Auto Disable account/Readme.md new file mode 100644 index 0000000000..ffa0cc6dc4 --- /dev/null +++ b/Server-Side Components/Scheduled Jobs/Auto Disable account/Readme.md @@ -0,0 +1 @@ +This schedule job script will help to auto disable the service accounts which has not been logged in or used for last 40 days. This can be helpful for those who are looking to disable the accounts based on some certain time period. From f7c9c3924e7ad6a6b8240974cc1cb2bdd2f402da Mon Sep 17 00:00:00 2001 From: Abhishek Thakur <146176327+at8807602@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:37:44 +0530 Subject: [PATCH 3/5] Disable Service accounts due to inactivity This is for disabling the Service account due to inactivity --- ...Disable Service accounts due to inactivity | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity b/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity index f352cb5432..25d2e8ef13 100644 --- a/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity +++ b/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity @@ -1,19 +1,25 @@ -var user = new GlideRecord("sys_user"); // Glide to user table -user.addActiveQuery(); -user.addEncodedQuery("u_service_account=true"); // Adding encoded query to filter the only Service Account +var user = new GlideRecord("sys_user"); +user.addActiveQuery(); +user.addEncodedQuery("last_login!=NULL"); user.query(); while (user.next()) { - var arr = []; // Definind an empty array - arr.push(user.user_name); // pushing all he usernames with in the array + var arr = []; + arr.push(user.last_login); for (var i = 0; i <= arr.length - 1; i++) { - var userID = arr[i]; - var query1 = "sys_created_onRELATIVELT@dayofweek@ahead@40^sys_created_by=" + userID; // creating a dynamic query to check if the account has any transaction in last 40 days on transaction table. - var tranSaction = new GlideRecord("syslog_transaction"); // Glide to the tranaction table - tranSaction.addEncodedQuery(query1); // adding an query1 - tranSaction.query(); - tranSaction.orderByDesc("sys_created_on"); - if (!tranSaction.next()) { - gs.print(arr); // this will print only user names which does not have any transaction in last 40 days on log transaction table. + var time = arr[i]; + var date1 = new GlideDate(); + date1.setValue(time); + var date2 = new GlideDate(); + var millisecondsDifference = date2.getNumericValue() - date1.getNumericValue(); + var daysDifference = millisecondsDifference / (1000 * 60 * 60 * 24); + var days = Math.floor(daysDifference); + if (days > 30) { + user.active = false; + user.locked_out = true; + user.update(); } + } + + } From a5e47401fbc4659a7fc05740e9dc0e79c94dd660 Mon Sep 17 00:00:00 2001 From: Abhishek Thakur <146176327+at8807602@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:38:50 +0530 Subject: [PATCH 4/5] Readme.md This schedule job script will help to auto disable the service accounts which has not been logged in or used for last 30 days. This can be helpful for those who are looking to disable the accounts based on some certain time period. --- .../Scheduled Jobs/Auto Disable account/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server-Side Components/Scheduled Jobs/Auto Disable account/Readme.md b/Server-Side Components/Scheduled Jobs/Auto Disable account/Readme.md index ffa0cc6dc4..76aa376aca 100644 --- a/Server-Side Components/Scheduled Jobs/Auto Disable account/Readme.md +++ b/Server-Side Components/Scheduled Jobs/Auto Disable account/Readme.md @@ -1 +1 @@ -This schedule job script will help to auto disable the service accounts which has not been logged in or used for last 40 days. This can be helpful for those who are looking to disable the accounts based on some certain time period. +This schedule job script will help to auto disable the service accounts which has not been logged in or used for last 30 days. This can be helpful for those who are looking to disable the accounts based on some certain time period. From f18fdf8a07029e3637eb731b97f2c929a4d16e64 Mon Sep 17 00:00:00 2001 From: Abhishek Thakur <146176327+at8807602@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:00:08 +0530 Subject: [PATCH 5/5] Disable Service accounts due to inactivity This code helps to disable the service account due to inactivity for last 30 days. --- .../Disable Service accounts due to inactivity | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity b/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity index 25d2e8ef13..746c907ff4 100644 --- a/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity +++ b/Server-Side Components/Scheduled Jobs/Auto Disable account/Disable Service accounts due to inactivity @@ -1,6 +1,6 @@ var user = new GlideRecord("sys_user"); user.addActiveQuery(); -user.addEncodedQuery("last_login!=NULL"); +user.addEncodedQuery("last_loginISNOTEMPTY^u_service_account=true"); user.query(); while (user.next()) { var arr = [];