Powershell - Delete Contacts from "Contacts" folder only

I'm working with an Exchange 2016 server (on-prem) and I'd like to run a PowerShell command to remove contacts from a user's mailbox, but only from the "Contacts" folder. If the user has any custom folders, I would not want to touch those.

search-mailbox -identity USERNAME -searchquery kind:contacts -deletecontent

Open in new window


This command works, but it deletes all contacts from all folders. Is there a way to restrict this command (or another like it) to only the default "Contacts" folder?
street9009Asked:
Who is Participating?
 
timgreen7077Exchange EngineerCommented:
Unfortunately their is now way to remove only the contacts in the exchange shell. the cmdlets you are running doesn't allow you to search a specific folder, and the target folder is the mailbox that will be used to return results, the targetmailbox and targetfolder are not being search with the search-mailbox cmdlets.

No you can't search contacts and delete with the shell. You will need to use OWA or outlook, to remove, or give yourself full manage access to the user's mailbox and delete the contacts, but using the exchange shell to search specific folders and delete will not work.
1
 
Ajay ChananaMCSE-2003/08|RHCSA| VCP5/6 |vExpert2018Commented:
Search-Mailbox -TargetFolder <String>


add target folder in the above query should work for you.
0
 
street9009Author Commented:
OWA and/or Outlook won't work as I need to be able to do this en-masse. Is there any kind of tool at all that can do this or am I out of luck?
0
 
timgreen7077Exchange EngineerCommented:
I would never say there is no 3rd party tool for that, but not one that i know of.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.