Hi @lletsweletse,
Thank you for posting your question in the Microsoft Q&A forum.
Based on your inquiry, we understand that you have considered to delete junk mail from over 65 thousands user on exchange 2019 on prem. We will be glad to assist you in this part.
According to your issue, using ComplianceSearch is likely the most optimal method for handling such a large number of mailboxes. The reason you are encountering issues with the ComplianceSearch command might be due to the Discovery Management role not being properly assigned, which is required to authorize the use of this command. If possible, please review the role settings on your server to ensure the necessary permissions are in place.
You can refer to this link: Search for and delete messages in Exchange Server | Microsoft Learn
Note: The "New-ComlianceSearch" cmdlet recommended that you add the user into the "Compliance Administrator" and "eDiscovery Manager" role groups. That is to say, you can re-confirm if you have added your account (the global admin) into the 2 role groups.
If possible, could you double check which module you using and syntax within your script? The error indicating that the command is not recognized could be cautioned from them. I understand how frustrating this can be, and I will effort to troubleshoot this for you.
You can refer via: Exchange cmdlet syntax | Microsoft Learn
Please let me know if you need further assistance, please let us know.
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.