Forum Discussion

jstump1972's avatar
jstump1972
Copper Contributor
Jul 10, 2020

Deleting malicious emails from all O365 mailboxes

Please assist me with a exch ps o365 script to remove email from all o365 mailboxes by subject line or sender email address. I cannot seem to find the right command to do in cloud. 

9 Replies

  • stevemorgan's avatar
    stevemorgan
    Copper Contributor

    jstump1972 

     

    "By default, Search-Mailbox is available only in the Mailbox Search or Mailbox Import Export roles, and these roles aren't assigned to *any* role groups. To use this cmdlet, you need to add one or both of the roles to a role group (for example, the Organization Management role group). Only the Mailbox Import Export role gives you access to the DeleteContent parameter."

    https://docs.microsoft.com/en-us/powershell/module/exchange/search-mailbox?view=exchange-ps

    • jstump1972's avatar
      jstump1972
      Copper Contributor

      example below - 

       

      PS C:\get-mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Search-Mailbox -SearchQuery 'subject:"JOB REFERRAL" -DeleteContent -force

       

      'Search-Mailbox : The term 'Search-Mailbox' is not recognized as the name of a cmdlet, function, script file, oroperable program. Check the spelling of the name, or if a path was included, verify that the path is correct and tryagain.At line:1 char:71+ ... Unlimited -RecipientTypeDetails UserMailbox | Search-Mailbox -Search ...+ ~~~~~~~~~~~~~~+ CategoryInfo : ObjectNotFound: (Search-Mailbox:String) [], CommandNotFoundException+ FullyQualifiedErrorId : CommandNotFoundException@stevemorgan

       

      stevemorgan 

      • stevemorgan's avatar
        stevemorgan
        Copper Contributor

        jstump1972 

         

        How are you connecting to Exchange Online? I just connected via V2 Module and it ran. Do you have the appropriate roles assigned? Did you reconnect after assigning to reload the appropriate cmdlets?

Resources