Hi LilyLi2 and Amit,
Thank you for your replies. Amit - yes I have looked at both articles, nothing that'll help this particular situation. LilyLi2 - we don't have any distribution lists on premises (or any other Exchange objects) anymore. I did find the Monitoring mailboxes and applied your suggested permissions to it, and then ran the cleanup script again, with the same result (errors).
The account that I run the PowerShell script on, on a Windows Server 2019 DC, is a Domain Admin, Enterprise Admin and Exchange Organization Management account.
I note that this line (101) in the script fails:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
If I run this line by itself in PowerShell I get:
PS C:\Users\pauls\Downloads> Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 5.
At line:1 char:1
- Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidArgument: (Microsoft.Excha...owerShell.E2010:String) [Add-PSSnapin], PSArgumentException
- FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
I suspect that's why subsequent commands fail.
Should this script be run on a DC? On an Exchange 2019 server? (I've now tried both, and it's failed on both). How can I load the Exchange snap in so that the Exchange cmdlets work?
Looking forward to your answer,
Paul Schnackenburg