$mailbox = write-output UserMailbox1 UserMailbox2; #Create Array mailbox $dateStart = (Get-date ((Get-Date).AddYears(-10)) -Format "dd.MM.yyyy").Replace(".","/"); #$dateStart search recived mails $dateEnd = (Get-date ((Get-Date).AddMonths(-1)) -Format "dd.MM.yyyy").Replace(".","/"); #$dateEnd search recived mails $SearchQuery = "received:" + $dateStart + ".." + $dateEnd; #received:20/12/2013..20/11/2023 ###search string $mailbox | Get-Mailbox -resultsize unlimited | Search-Mailbox -SearchQuery $SearchQuery -EstimateResultOnly #Show the number of emails found $mailbox | Get-Mailbox -resultsize unlimited | Search-Mailbox -SearchQuery {$SearchQuery} –DeleteContent –Force #Delete found emails