Hello @Bosco Das ,
Is it possible to process the task via AD attribute for the DG?
I understand your needs, however, at present, after testing in my environment, there is no determination of any parameters to achieve this purpose. In order to solve your problem, may I know how do you remove the Exchange server on-prem? If your operation is only shut down the server, and use the script to clean up, you could still use PowerShell to manage the on-prem recipient. For more information, you could refer to https://learn.microsoft.com/en-us/exchange/manage-hybrid-exchange-recipients-with-management-tools. If it is in other cases, we will continue to study to see if we can find other solutions.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in [our documentation] to enable e-mail notifications if you want to receive the related email notification for this thread.