Delete a single folder within Contacts for a Exchange 2013 Mailbox
We have a cell phone contact list that is saved as a subfolder called "Cell Phone List" in a otherwise empty PST file. Once a month a script runs that pulls a list of mailboxes from a text file, deletes all contacts with our company name, deletes the dumpster, and adds them back in like this:
foreach ($i in (Import-Csv "\\File\Share\ContactSync.txt")) { Search-Mailbox -Identity $i.alias -SearchQuery 'kind:contacts AND subject:" - CompanyName"' -DeleteContent -Force }
foreach ($i in (Import-Csv "\\File\Share\ContactSync.txt")) { Search-Mailbox -Identity $i.alias -SearchQuery 'kind:contacts' -SearchDumpsterOnly -DeleteContent -Force }
foreach ($i in (Import-Csv "\\File\Share\ContactSync.txt")) { New-MailboxImportRequest -Mailbox $i.alias -FilePath "\\File\Share\PhoneContacts.pst" -TargetRootFolder "#Contacts#" }
This works great about 98% of the time and those peoples cell phones (ActiveSync) see the change and resync. That last 2% however the cell phones see the contacts deleted but don't sync the replacements. To fix those we manually delete the "Cell Phone List" subfolder out of their contacts, do the import again, and it works.
So our best guess is something in activesync doesn't see a change and wont sync but does see the subfolder delete and when it's back does sync properly. With that said I cannot figure out a way to delete a subfolder using a simple one line command from the contacts folder. Does that exist? I've found lots of examples on using Search-Mailbox for actual contacts and mail items but none to delete a specific folder.
Solution 1:
Cmdlet Search-Mailbox
has no parameters to delete a specific folder, the following link about the cmdlet is for your reference: Search-Mailbox.
Besides, I also tried to run the following command in Exchange 2013 PowerShell, but I didn't find any command to remove specific folders:
Get-Command | where{$_.Name -like "*Remove*" -and $_.Name -like "*Folder*"} | ft Name -AutoSize
Get-Command | where{$_.Name -like "*Folder*"} | ft Name -AutoSize
Based on my research, I found a similar thread: Delete Folder from all Mailboxes on Exchange 2016 with Powershell, as Vasil L. Michev/KevDrummond and others answered, you could use EWS to delete specific folders.
Hope the above info is helpful to you!