remove users that are not logged in since 90 days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2016 11:53 PM
I have requirement where in I have to remove all users role and group if they haven't logged in since 90 days or inactive for 30 days.
I am not able to get approach and script for this needed help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2016 03:01 AM
Create a scheduled job, compare last login time with current date time.
If its more than 30 days, set active true and lockout true.
If more than 90 days, you can delete the user record.
Mrinmoy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2016 03:56 AM
Hey Mrinmoy,
Can you please provide script for this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2016 10:28 AM
Nikhil,
Make sure your conditions you want to apply before executing this, because this involves deleteMultiple();
Script:
var gr= new GlideRecord('sys_user');
gr.addEncodedQuery('active=true^last_loginRELATIVELT@dayofweek@ago@90'); // this gets all the users who are active and last logged in 3 months(90) ago
gr.query();
while(gr.next()){
var gr2= new GlideRecord('sys_user_grmember');
gr2.addQuery('user',gr.sys_id);
gr2.query();
gr2.deleteMultiple(); //deletes the user from the groups
var gr1= new GlideRecord('sys_user_has_role');
gr1.addQuery('user',gr.sys_id);
gr1.query();
gr1.deleteMultiple(); // deletes all the roles the user have
}
Thanks,
Abhinay
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2022 09:50 AM
Hi mrinmoy,
Last login date and current date time comparing fine but how to write logic if its more than 30 days in Java coding.
Thanks
Rohit