locked
delete an email from inbox RRS feed

  • Question

  • Hi experts

    We have received spam email to few of my users. i need to delete that spam email from users mailbox.

    i have the information of my users i.e user1@mydomain.com and description: spammsg.

    i have exported the users list to csv format.

    experts guide me with powershell command to delete the msg.

    Wednesday, April 11, 2018 7:29 AM

Answers

  • Hi Risingflight,

    Take steps below to achieve your goal:
    1. Open ECP, permissions, admin roles, then create a new role group with Mailbox Import Export and Mailbox Search permission,  add administrator to this group. (Those permission are needed for search-mailbox command) 
    2. Create a CSV file and input mailboxes which have spam.
     
    3. Create a PS1 file showed in the picture below: 
    4. Run the script in EMS. 

    This function of this script is search mailbox which showed in picture two and delete mail which subject is “new” from those mailboxes.
    For more information about search-mailbox, you can see:  https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/search-mailbox?view=exchange-ps


    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, April 12, 2018 8:12 AM
  • Hi Risingflight,

    Yes, you can. 

    -SearchQuery 'From:"administrator@contoso2.com" AND Subject:"Test2"'

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by Risingflight Tuesday, April 24, 2018 4:20 PM
    Monday, April 23, 2018 2:09 AM

All replies

  • Hi Risingflight,

    Take steps below to achieve your goal:
    1. Open ECP, permissions, admin roles, then create a new role group with Mailbox Import Export and Mailbox Search permission,  add administrator to this group. (Those permission are needed for search-mailbox command) 
    2. Create a CSV file and input mailboxes which have spam.
     
    3. Create a PS1 file showed in the picture below: 
    4. Run the script in EMS. 

    This function of this script is search mailbox which showed in picture two and delete mail which subject is “new” from those mailboxes.
    For more information about search-mailbox, you can see:  https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/search-mailbox?view=exchange-ps


    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, April 12, 2018 8:12 AM
  • Hi experts i am getting the below error, i have also created role group 

    search-mailbox : The term 'search-mailbox' is not recognized as the name of a cmdlet, function, script file, or
    operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
    again.
    At C:\edelete.ps1:3 char:1
    + search-mailbox -Identity $mailbox.Name -SearchQuery 'Subject:"test1"' -DeleteCon ...
    + ~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (search-mailbox:String) [], CommandNotFoundException


    Sunday, April 15, 2018 6:54 AM
  • Hi Risingflight,

    Please make sure the one who runs the EMS is in this group which contains Mailbox Import Export and Mailbox search roles. If you run EMS as other users, you need add that user to this group.

    After adding users to this group, you need to reopen EMS and run this script.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, April 16, 2018 1:37 AM
  • The above solution works prefect.

    is it possible to delete an email mentioning sender id, recipient id and subject.

    Friday, April 20, 2018 6:27 PM
  • Hi Risingflight,

    Yes, you can. 

    -SearchQuery 'From:"administrator@contoso2.com" AND Subject:"Test2"'

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by Risingflight Tuesday, April 24, 2018 4:20 PM
    Monday, April 23, 2018 2:09 AM
  • Thanks alot works perfectly
    Tuesday, April 24, 2018 4:20 PM