Search-Mailbox command now failing. Has something to do with attachment size


  • We have been using the command below for years searching through mailboxes to remove spam or possibly malicious emails. Always worked great. We run it first in logLevel Full mode and then add the -DeleteContent Switch.

    get-mailboxserver | Get-Mailbox -resultsize unlimited | Search-Mailbox -SearchQuery "From:"" -TargetMailbox "Suspect Emails" -TargetFolder "Phish" -LogLevel Full

    Recently when running the command we are now getting the error below. I know the reason why we are getting the error. I just don't know what to do to fix it. The queries we are running now are returning much larger results. Basically every mailbox and it looks like it cannot create the Excel worksheet. If I run it on each mailbox server separately, it seems to run OK because I am only hitting half the mailboxes. Is there a swtich or setting I can implement to override this error?

    Cannot open attachment.
        + CategoryInfo          : InvalidArgument: (:) [], AttachmentExceededException
        + FullyQualifiedErrorId : 274AF090

    2018年5月18日 13:47


  • Hi shadowtuck,

    Could you use the command below to search for just one mailbox successfully?

    Search-Mailbox -SearchQuery {From:""} -TargetMailbox "" -TargetFolder "xxx" -LogLevel Full

    I guess there has a limit about search-mailbox, if you can search for just on mailbox, you can use the script below to search for all mailbox:

    $mailboxes = Get-MailboxServer | Get-Mailbox -resultsize unlimited
    foreach($mailbox in $mailboxes){
    Search-Mailbox -Identity $ -SearchQuery {From:""} -TargetMailbox "xxx" -TargetFolder "xxx" -LogLevel Full


    Kyle Xu

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

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

    2018年5月21日 6:13
  • Yes, I can search one mailbox. In fact, I can search over a thousand mailboxes but there seems to be a limit in regards to the creation of the attachment when loglevel is set to full.

    This is the problem I am trying to solve. I can run the command against a single mailbox with half our mailboxes on it and it works, but if I run it against all mailboxes, if fails creating the attachment.

    2018年5月23日 11:23