Missing Journal mails

Good morning all.

I am hoping that someone can assist with a powershell command or alternative.

What I am trying to do: I need to do a mailboxseach for a specific user. Specifically, I need all mails sent to user@domain.com from all users in the same domain @domain.com

Example: find all mails from @domain.com to peter@domain.com

Currently I am using this command:

Get-Mailbox -Identity stefan@domain.co.za -ResultSize Unlimited | New-MailboxSearch -MessageTypes Email -TargetMailbox administrator@domain.co.za -StartDate 04/22/2018 -Name JournalExport -Senders *@domain.co.za -Recipients stefan@domain.co.za

The above command works almost 100%, but there are still mails to the user from external domains. I only need internal emails.

Currently we have a gap in our internal journal (standard Journaling) and I am trying to fill that gap with the mails still in the mailbox.
technolutionsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeTwo SoftwareSoftware DeveloperCommented:
Hi technosolutions,
According to the TechNet documentation, the -Senders attribute does not support wildcards. At the same time, it should support domains. If you change it to -Senders "domain.co.za", it should work. Alternatively, use -SearchQuery '(from: "*@domain.co.za")' instead of the -Senders filter
technolutionsAuthor Commented:
Thank you very much for the tip. I ended up using the Searchquery as it gave me the best results.

I am also hoping that you can assist with the second part of my question that I am now stuck with.

With the above command, the emails are copied to the journal mailbox under a folder called journalExport. I now have to move the mails from that folder to the inbox. The journal provider can only pull mails from the inbox so I can't simply pull from that folder.

With the amounts of data needed to pull, the manual way is also not feasible.

Currently my command looks like this:
.\MoveEmails.ps1 -MailboxName administrator@domain -SourceFolder "JournalExport" -TargetFolder "inbox" -TargetType primary -username Administrator_WF -password "MG4ZCUFswdx"

The movemails script is one I found on the internet, but the error below is stopping me:

Error: The account does not have permission to impersonate the requested user.

I have added the permissions and roles to the group as suggested by the script writer, waiting for AD to replicate and ever forced after 24 hours.

Still no luck.

Really hope you can help.

Thanks
CodeTwo SoftwareSoftware DeveloperCommented:
I hope it is not a real password you have pasted in above...
Now you make me wonder... Wouldn't it be a bit easier to use your original command to copy the results to inbox? The second procedure wouldn't be necessary then. You could try changing your script to:
Get-Mailbox -Identity stefan@domain.co.za -ResultSize Unlimited | Search-Mailbox -TargetMailbox administrator@domain.co.za -TargetFolder "inbox" -SearchQuery '(from: "*@domain.co.za") AND (to:"stefan@domain.co.za") AND (received>=04/22/2018)'

Open in new window

When it comes to the script - I am afraid I am not familiar with this one. But judging from the error you specify, something went wrong when configuring the impersonation rights. You can try following the steps specified in How to set impersonation rights manually to make sure you have configured impersonation correctly.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

technolutionsAuthor Commented:
THank you very much. I will give it a try,

Do you know if the command MOVES or COPIES the mails? I do not want it to move the mails out of the original users mailbox.

Thanks again.
CodeTwo SoftwareSoftware DeveloperCommented:
Search-Mailbox cmdlet with this syntax copies the emails.
If you ever wanted to use it for "moving" emails, you would have run the cmdlet again, after substituting -TargetMailbox and -TargetFolder with the -DeleteContent switch. If you want to copy emails, leave it as it is.
technolutionsAuthor Commented:
Thank you so much! You are a legend. The above command seems to work just fine and is much better then taking two steps.

The only problem that I am having is that the mails are copied into a subfolder as per the image. Do you know of a way to prevent this? Screen-Shot-2018-04-25-at-15.10.35.png
CodeTwo SoftwareSoftware DeveloperCommented:
Thank you, I am glad I could help!
Unfortunately, I will not be able to help you with the last question. As far as I know, the cmdlet is designed to work this way and there is no easy workaround to prevent this behavior.
technolutionsAuthor Commented:
Thank you again for your assistance. it helped me to understand the formatting of the scripts a lot better.

Sad I couldn't get the end result I was hoping for :-(
technolutionsAuthor Commented:
Thanks for the great info and help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.