How to Logout all the user that are currently logged In from the Instance

ravish2
Giga Expert

I want to make sure that all the user which are currently logged in should be locked out before starting my maintenance work.

Is it possible by anyway using script or anything ?

1 ACCEPTED SOLUTION

Ravish,



It does not kick current users out but prevents them from logging back in. Used in combo with Alex's suggestion that should do what you need.



var gr = new GlideRecord('v_user_session');


gr.addEncodedQuery('user!=YOURIDHERE');


gr.query();


while(gr.next()){


gr.locked = true;


}


View solution in original post

9 REPLIES 9

Ravish,



It does not kick current users out but prevents them from logging back in. Used in combo with Alex's suggestion that should do what you need.



var gr = new GlideRecord('v_user_session');


gr.addEncodedQuery('user!=YOURIDHERE');


gr.query();


while(gr.next()){


gr.locked = true;


}


 

Setting gr.locked = true on v_user_session table only locks out users in a specific node (Node in which the script runs).

An Instance may have more than 2 nodes, in that case we are not killing all the sessions for all the users. 

To forcefully terminate all the active user session on all nodes for all the user, use the below function in server side scripts by looping with all the user_names who's session needs to be killed.

GlideSessions.lockOutSessionsInAllNodes(<user_name>);

 

This would kill the sessions and logout users who are currently logged in when they perform their next action.

 

 

ashik1
Kilo Guru

Hi


I have a similar requirement but I need to logout all users.


'v_user_session' table holds user session who are in same node as yours.


Managing User Sessions - ServiceNow Wiki



How do i get list of all logged in users


Hi Ashik,



Please check if this helps: Capture the users login for all the nodes.


Hi Ashik,



We also had a similar requirement to forcefully terminate all the active user session on all nodes for a user


and it was achieved by using the below function in server side scripts.


GlideSessions.lockOutSessionsInAllNodes(<user_name>);