Admin role for running background script

Aniket6
Kilo Contributor

I want to run a background script for removing inactive admin users. This script is supposed to remove roles from groups of an admin user who is no longer a part of the organization. For this purpose, I have written a background script to remove admin users.  I wanted to know what should be the Run As Field. Using the blank option for the Run As field is supposed to run as an admin but does not remove the users from having the admin role. I however do not want to have the run as field as an admin user from the list of employees. Is there any default admin role provided by ServiceNow for the same which I can use for the Run As to remove roles from users

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Aniket,

run as should be always System Administrator user with user_name as admin; there will always be 1 for every instance.

Ensure in your script you don't remove admin from system administrator user accidentally

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Jaspal Singh
Mega Patron
Mega Patron

Hi Aniket,

 

There always exists one 'System Administrator' profile with admin & security_admin role always for all instances. This can be used as 'Run as: ' User always for any background scripts.

Also, since you would be using Scheduled job better do a check for the script in background script to ensure the count of admins you get so as to ensure that when script executes only the invalid ones are revoked from Groups & Roles table.