Skip to content

Commit be1fd1a

Browse files
authored
Auto Disable the Service Accounts due to inactivity (#1646)
* 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. * Create Readme.md This file gives the information about the above file for auto disabling the service accounts * Disable Service accounts due to inactivity This is for disabling the Service account due to inactivity * 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. * Disable Service accounts due to inactivity This code helps to disable the service account due to inactivity for last 30 days.
1 parent fded483 commit be1fd1a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var user = new GlideRecord("sys_user");
2+
user.addActiveQuery();
3+
user.addEncodedQuery("last_loginISNOTEMPTY^u_service_account=true");
4+
user.query();
5+
while (user.next()) {
6+
var arr = [];
7+
arr.push(user.last_login);
8+
for (var i = 0; i <= arr.length - 1; i++) {
9+
var time = arr[i];
10+
var date1 = new GlideDate();
11+
date1.setValue(time);
12+
var date2 = new GlideDate();
13+
var millisecondsDifference = date2.getNumericValue() - date1.getNumericValue();
14+
var daysDifference = millisecondsDifference / (1000 * 60 * 60 * 24);
15+
var days = Math.floor(daysDifference);
16+
if (days > 30) {
17+
user.active = false;
18+
user.locked_out = true;
19+
user.update();
20+
}
21+
22+
}
23+
24+
25+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
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.

0 commit comments

Comments
 (0)