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 09:59 AM
Nikhil,
Use the below script, same we had a requirement and implemented.
var gR=new GlideRecord('sys_user_has_role'); // go to user role table
gR.addEncodedQuery('user.last_login_timeISEMPTY^ORuser.last_login_timeRELATIVELE@dayofweek@ago@30^user.active=true^user.locked_out=false');//check the conditions like user record is active, last login time etc...
gR.query();
while(gR.next())
{
var SID=gR.user; // get the user details
var gR1=new GlideRecord('sys_user_grmember');
gR1.addQuery('sys_id',SID);
gR1.query();
if(gR1.next())
{
gR1.deleteMultiple(); // remove the user from the group
}
gR.deleteMultiple(); // delete the roles of those users.
}
Regards:
Suresh. D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2016 10:29 AM
Hi Nihil,
When you say ".. remove all users role and group" do you mean remove all the roles and groups associated with user who has not logged in in the last 90 days?
Deleting users, for example, is not recommended.
Deleting users can lead to Incidents without defined callers and other odd and undesirable outcomes.
Best Regards
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 09:38 AM
How to get that encoded query