Purpose of the Script: This script automatically finds and cleans up user accounts that meet all of the following conditions:
- The user is inactive
- The user is locked out
- They haven’t been updated in the last 90 days
For such users, the script:
- Removes them from all groups
- Deletes all their roles
- Logs everything in the system logs
Explanation:
- Set a time threshold (90 days):
- It calculates the date 90 days ago from today.
- Find target users:
- Searches the sys_user table for users who:
- Are marked as inactive
- Are locked out
- Have not been updated since 90 days ago
- Searches the sys_user table for users who:
- Loop through each matching user:
- Logs the username being cleaned up
- Remove user from all groups:
- Searches the sys_user_grmember table (group memberships)
- Deletes all group entries related to the user
- Remove all roles:
- Searches the sys_user_has_role table
- Deletes all roles assigned to the user
- Logs the total number of users processed.