Skip to content

Commit 80b7f89

Browse files
Create Readme.md
Auto deactivate inactive users while informing their manager
1 parent d416c9c commit 80b7f89

File tree

1 file changed

+43
-0
lines changed
  • Server-Side Components/Scheduled Jobs/Auto deactivate the inactive users

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Purpose
2+
This scheduled job automatically identifies inactive users in the ServiceNow instance and deactivates their accounts if they have not logged in for a specified period (default: 3 months).
3+
It ensures compliance, reduces clutter, and maintains security by removing stale user accounts.
4+
5+
Key Features
6+
Runs automatically once per month.
7+
Identifies users who have been inactive for a defined number of months.
8+
Supports dry-run testing to safely validate before applying changes.
9+
Deactivates inactive users automatically.
10+
Sends email notifications to both users and their managers upon deactivation.
11+
Logs all activities in the system log for auditing purposes.
12+
13+
Script Workflow
14+
15+
1. Calculate Cutoff Date
16+
The script calculates a cutoff date by subtracting the configured number of months (default: 3) from the current date.
17+
Any user created before this date and who has not logged in since is considered inactive.
18+
19+
2. Query Eligible Users
20+
The script searches the sys_user table for records meeting these conditions:
21+
active = true
22+
sys_created_on <= cutoffDate
23+
last_login_time <= cutoffDate
24+
25+
3. Process Each User
26+
For every matching user, the script:
27+
Logs user details (name, email, last login, manager).
28+
Deactivates the account (if DRY_RUN is false).
29+
Sends notification emails.
30+
31+
4. Send Notification to User
32+
Sends a plain-text email to the user informing them that their account was deactivated due to inactivity.
33+
Includes instructions on how to request reactivation.
34+
35+
5. Send Notification to Manager
36+
If the user has a manager assigned, an additional email is sent to the manager.
37+
The email contains the user’s details and the date of last login for awareness.
38+
39+
6. Log Summary
40+
At the end of execution, the script logs:
41+
Total users found
42+
Total users deactivated
43+
Status of the run (Dry Run or Actual)

0 commit comments

Comments
 (0)