Deleting contacts from a 365 shared mailbox

Hello all,
I have been struggling for several hours to figure out how to delete all contacts from a shared mailbox in Microsoft 365. To no avail. I can import contacts from a CSV successfully, but any further import just adds the contacts anew. So I need to delete the old ones before importing. And of course I need that automated. I have everything figured out and working except the deletion part.
Remove-MailContact -Identity heregoestheuser ends with an error of “object couldn’t be found”
If anybody has any idea how to do it, I would be eternally grateful

More detail would be nice, like your exact code and error message? Based on the limited info provided, it looks like there is an issue with “heregoestheuser” … are you providing that as a result from Get-AdUser ? I do not manage Exchange nor do I have the ability to test.

Hi Tony,
I figured it out yesterday. I needed for the admin to be a have access to MailboxSearch in Exchange. Then Search-Mailbox command would be available in Powershell.
After that Search-Mailbox command became available with wihich I managed to delete the contacts as well.
Search-Mailbox -identity heregoestheuser@somecompany.com -searchquery kind:contacts -deletecontent -Force

Great news, glad you got it figured :slightly_smiling_face: