Retain Specific AD Group Memberships After Termination

In One Identity Manager, when an employee is terminated, AD group memberships are removed. I know the "Retain groups if permanently disabled" option can retain all group memberships, but my requirement is to retain membership in only two specific AD groups while removing all others.

What is the recommended way to achieve this? Has anyone implemented a solution using custom processes, scripts, or exclusion logic? I am using 9.3.1 version.

Thanks.