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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ajay ChananaMCSE-2003/08|RHCSA| VCP5/6 |vExpert2018Commented:
Search-Mailbox -TargetFolder <String>

add target folder in the above query should work for you.
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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?
timgreen7077Exchange EngineerCommented:
I would never say there is no 3rd party tool for that, but not one that i know of.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.