deleting old mail from users db exchange 2016. what is the right command from powershell?

Copper Contributor

Good morning,
in these days I am archiving/storing the old mail on the exchange server 2016 of mailboxes until 01/01/2019, once the mailboxes have been exported to .pst I delete the mails with the following command:
Search-Mailbox -Identity mailbox -SearchQuery 'Received <01/01/2019' -DeleteContent -Force
I found, however, that with this command all the additional information of the mailbox are deleted as well as the mails also contacts <01/01/2019 calendars, notes, etc., the verification I did with the following command
Search-Mailbox -Identity mailbox -SearchQuery 'Received <01/01/2019' -LogOnly -LogLevel full -TargetMailbox (mailboxname) -TargetFolder search
so I used the following command to delete only the emails:
Search-Mailbox -Identity mailbox -SearchQuery {(kind: Email) -lt 'Received <01/01/2019'} -DeleteContent -force
also launching a log on the command, however, some old emails prior to 01/01/2019 remain and I can not delete them except by hand.
what am i doing wrong in the command kind: email?
can you give me the precise command to delete only the emails and not all the rest?
I have been trying to find the precise command for 2 weeks now but I can't, can you help me out?
THANK YOU VERY MUCH
Yours sincerely

0 Replies