# Deleting contacts from a 365 shared mailbox

**URL:** <https://forums.powershell.org/t/deleting-contacts-from-a-365-shared-mailbox/16832>\
**Category:** PowerShell Help\
**Created:** [June 16, 2021, 8:19am UTC](https://forums.powershell.org/t/deleting-contacts-from-a-365-shared-mailbox/16832 "2021-06-16T08:19:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DenisC](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@DenisC](https://forums.powershell.org/u/DenisC)\
**Post date:** [June 16, 2021, 8:19am UTC](https://forums.powershell.org/t/deleting-contacts-from-a-365-shared-mailbox/16832/1 "2021-06-16T08:19:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [June 17, 2021, 4:24pm UTC](https://forums.powershell.org/t/deleting-contacts-from-a-365-shared-mailbox/16832/2 "2021-06-17T16:24:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DenisC](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@DenisC](https://forums.powershell.org/u/DenisC)\
**Post date:** [June 18, 2021, 6:00am UTC](https://forums.powershell.org/t/deleting-contacts-from-a-365-shared-mailbox/16832/3 "2021-06-18T06:00:22Z")

</div>

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](mailto:heregoestheuser@somecompany.com) -searchquery kind:contacts -deletecontent -Force

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [June 18, 2021, 3:23pm UTC](https://forums.powershell.org/t/deleting-contacts-from-a-365-shared-mailbox/16832/4 "2021-06-18T15:23:55Z")

</div>

Great news, glad you got it figured 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:24pm UTC](https://forums.powershell.org/t/deleting-contacts-from-a-365-shared-mailbox/16832/5 "2024-05-16T20:24:13Z")

</div>

Closed on May 16, 2024, 8:24pm UTC


