Add users to groups in the course of deprovisioning

Dear all,

following challenge:

We've got a script checking if users that are deprovisioned are present in multiple ancillary systems. This is checked based on different AD criterias, e.g. presence of certain fields or even group memberships.

Check results in an E-Mail being produced stating in which systems the user was found. This all is working fine.

However, I would like to enhance the check by adding the users to different groups depending on the identified ancillary system.

Including this in the initial script wouldn't work as a later stage in the deprovisioning process is the standard step to remove the object from all groups.

Creating an additional script to be ran after removing from groups won't work either as at least one ancillary is detected by way of a group membership which won't be detected as groups were removed.

Any hint / brilliant idea as of how this could be achieved?

Thanks a lot for your inputs.