Deleting contacts from a 365 shared mailbox

Copper Contributor

Hello all,
I have been struggling for several hours to figure out how to delete all contacts from a shared mailbox in Microsoft 365 using Powershell. 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.

7 Replies

@Denis_Christov 

Bonjour
avez vous utilisé ce script comme import des contacts csv vers le mailbox ?

Import-ContactList -CSV -CSVData ([System.IO.File]::ReadAllBytes("C:\xxxxx.csv")) -DateCultureName "en-GB" -Identity xxxx@domaine.onmicrosoft.com ?

 

si oui , c'était quoi la commande lancer pour la supression contact ?

@Kais_mbarki 

Hi Kais,

 

I use similar script:

Import-ContactList -Identity someone@comapany.com -CSV -CSVData ([System.IO.File]::ReadAllBytes("c:\temp\sample.csv"))

 

That one works correctly.

For deletion I tried

Remove-MailContact -Identity someone@company.com

But it says that "object couldn't be found" for that identity

 

I'm running it all under global admin account.

dans la commande import : vous avez utilisé -Identity UserpricipaleName ?
Remove-MailContact -Identity xxxxx est destiné pour les contact global du teant pour tous les utilisteurs et non pas pour une seul mailbox ...
a suivre j'ai le même soucis pour une boite à lettre d'un utilisteur
Aha. So it is not for a particular mailbox.
Hmmm. When it is possible to import contacts via Powershell, it SHOULD be possible to delte them with Powershell as well, right ? Maybe Microsoft considerd it unnecessary....

@Kais_mbarki Bonjour, j'aurais aimé savoir si vous aviez eu du changement dans cette question ? J'essaie aussi d'effacer les contacts d'un utilisateur. Je suis capable d'en importer mais pas effacer.

 

Mise à jour ! J'ai réussi avec    

Search-Mailbox -identity USER -SearchQuery kind:contacts -deletecontent
Yes, that is exactly what worked for me :)