locked
Delete mailbox content RRS feed

  • Pergunta

  • I should delete all mailboxes with a certain domain (e.g. daniele@contoso.com and not giovanni@microsoft.it) in a range of data.

    The command for all the boxes should be:

    foreach ($ mailbox in (get-mailbox)) {Search-Mailbox -id $ mailbox -SearchQuery '(Received: 01/01/2010..31/03/2020)' -DeleteContent -Force}

    But how can I filter by domain?
    sexta-feira, 17 de julho de 2020 15:24

Respostas

  • Hi,

    please use the code button when posting code. It makes reading it so much easier and copying it possible.

    To filter by domain (I assume, we are talking about the *primary* SMTP address since both Daniele and Giovanni could easily have an alias from the other domain), just modiy your Get-Mailbox selection:

    Get-Mailbox -Filter "WindowsEmailAddress -like '*@contoso.com'"


    Evgenij Smirnov

    http://evgenij.smirnov.de

    • Marcado como Resposta Daniele Gaibotti segunda-feira, 20 de julho de 2020 07:12
    sexta-feira, 17 de julho de 2020 17:20

Todas as Respostas

  • Hi,

    please use the code button when posting code. It makes reading it so much easier and copying it possible.

    To filter by domain (I assume, we are talking about the *primary* SMTP address since both Daniele and Giovanni could easily have an alias from the other domain), just modiy your Get-Mailbox selection:

    Get-Mailbox -Filter "WindowsEmailAddress -like '*@contoso.com'"


    Evgenij Smirnov

    http://evgenij.smirnov.de

    • Marcado como Resposta Daniele Gaibotti segunda-feira, 20 de julho de 2020 07:12
    sexta-feira, 17 de julho de 2020 17:20
  • Hi Daniele,

    The cmdlet below can also be used for your Get-Mailbox selection:

    Get-Mailbox -ResultSize Unlimited | Where-Object {($_.PrimarySMTPAddress -like "*@contoso.com")}

    I tested in my lab using the command below to delete mailbox content within contoso.com and it works fine: 

    Get-Mailbox -ResultSize Unlimited | Where-Object {($_.PrimarySMTPAddress -like "*@contoso.com")} | Search-Mailbox -SearchQuery {Received:"2020/1/1..2020/3/31"} -DeleteContent -Force

    Before deleting the mailbox content, you can replace "-DeleteContent -Force" with "-EstimateResultOnly" to have a look at the estimated number of the items that would be deleted. 

    Hope this can be helpful.

    This Exchange Server 2010 Forum will be migrating to a new home on Microsoft Q&A, please refer to this sticky post for more details.

    Regards,

    Yuki Sun


    Exchange Server 2010 forum will be migrating to a new home on Microsoft Q&A! We invite you to post new questions in the new forum.

    For more information, please refer to the sticky post.



    segunda-feira, 20 de julho de 2020 06:04
  • Hi, thanks for the tips.
    Evgeny's string works, but Yuki's doesn't work in my case.
    So I solved it like this:

    foreach ($mailbox in (Get-Mailbox -Filter "WindowsEmailAddress -like '*@contoso.it'")) {Search-Mailbox -id $mailbox -SearchQuery '(Ricevuti:20/07/2020..20/07/2020)' -DeleteContent -Force}

    Obviously the date must be changed according to your format and "Ricevuti" in Italian must be written in the exchange installation language.

    Thank you all.

    segunda-feira, 20 de julho de 2020 07:33
  • Hi Daniele,

    Great to know that you have sorted it out and thanks for your sharing! 

    Below is a brief summary of this thread for quick reference:

    Request/Expectation:
    You want to delete all mailboxes with a certain domain (e.g. daniele@contoso.com and not giovanni@microsoft.it) in a range of date.

    The command for all the boxes should be:
    foreach ($ mailbox in (get-mailbox)) {Search-Mailbox -id $ mailbox -SearchQuery '(Received: 01/01/2010..31/03/2020)' -DeleteContent -Force}

    You would like to know how to filter the domain in the get-mailbox string.

    Solution Summary:

    foreach ($mailbox in (Get-Mailbox -Filter "WindowsEmailAddress -like '*@contoso.com'")) {Search-Mailbox -id $mailbox -SearchQuery '(Ricevuti:20/07/2020..20/07/2020)' -DeleteContent -Force}

    (The date must be changed according to your format and "Ricevuti" in Italian must be written in the exchange installation language.)

    This Exchange Server 2010 Forum will be migrating to a new home on Microsoft Q&A, please refer to this sticky post for more details.

    Regards,

    Yuki Sun


    Exchange Server 2010 forum will be migrating to a new home on Microsoft Q&A! We invite you to post new questions in the new forum.

    For more information, please refer to the sticky post.


    segunda-feira, 20 de julho de 2020 07:51