File tree 2 files changed +37
-0
lines changed
Background Scripts/Logout User
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ logOutAllUsers ( 'admin' ) ; // Admin user is ignored.
2
+
3
+ function logOutAllUsers ( ignoreUser ) {
4
+ var logoutCounter = 0 ;
5
+ var grSession = new GlideRecord ( "v_user_session" ) ;
6
+ if ( ignoreUser && ignoreUser != '' ) {
7
+ grSession . addQuery ( "user" , "!=" , ignoreUser ) ;
8
+ }
9
+ grSession . query ( ) ;
10
+
11
+ while ( grSession . next ( ) ) {
12
+ var username = grSession . user ;
13
+
14
+ // Try to find the user record, based on their username.
15
+ var grUser = new GlideRecord ( "sys_user" ) ;
16
+ grUser . addQuery ( "user_name" , username ) ;
17
+ grUser . setLimit ( 1 ) ;
18
+ grUser . query ( ) ;
19
+
20
+ if ( grUser . next ( ) ) {
21
+ // Logout the user
22
+ gs . print ( "Logging out session for user " + username + "." ) ;
23
+ logoutCounter += 1 ;
24
+ grSession . locked = true ;
25
+ grSession . update ( ) ;
26
+ }
27
+ }
28
+ gs . print ( "Completed logout of " + logoutCounter + " users." ) ;
29
+ }
Original file line number Diff line number Diff line change
1
+ # Logout Users
2
+ Used to log out all users within the platform.
3
+
4
+ ## Usage
5
+ Run script in ** logoutUser.js** in 'Scripts - Background'
6
+
7
+ * ** Parameters:**
8
+ - ** ignoreUser:** Username of a sys_user that is ignored (ex. 'admin')
You can’t perform that action at this time.
0 commit comments