Force logout User(s) from background script
Please hit Like or Bookmark this article if it helps.
Use Case 1: Log out all users who are currently logged into ServiceNow before an outage. Usually we communicate to all the users about the outage days before the actual Outage start date. But just to make sure no one is currently logged into the instance during the outage, we can run the below background script few minutes before the actual outage start time.
var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('active=true^locked_out=false^user_name!='+gs.getUserName());
userGr.query();
while(userGr.next()){
var userName = userGr.getValue('user_name');
GlideSessions.lockOutSessionsInAllNodes(userName);
}
Output:
locked_out user abel.tutor
locked_out user julio.curry
locked_out user sergio.chang
locked_out user ramon.amaral
locked_out user Howard.Lewis
......
.....
....
...
..
.
Use Case 2: Annoy a friendly co-worker by logging them out
var userName = 'your coworkers user name';
GlideSessions.lockOutSessionsInAllNodes(userName);
Thank you,
Aman Gurram
ServiceNow Systems Integration Specialist
Helpful links:
Force Logout Users in all Nodes
How to Logout all the user that are currently logged In from the Instance
https://www.servicenow.com/community/developer-articles/force-logout-user-s-from-background-script/ta-p/2313637