Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This script is used in ServiceNow to remove the admin role from all users except the one running the script.
It's typically used during a security audit or access cleanup to ensure that only authorized users retain administrative access.
By targeting the sys_user_has_role table and checking for the admin role, it deletes role assignments for all users except the current user, helping reduce the risk of
unauthorized changes or privilege misuse in the system.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var adminRoleID = 'INSERT_ADMIN_ROLE_SYS_ID';
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('role', adminRoleID);
gr.query();

while (gr.next()) {
var userID = gr.user.sys_id + '';
if (userID !== gs.getUserID()) { // Keep current user safe
gr.deleteRecord();
}
}
Loading