Avatar of Cyprexx IT
Cyprexx IT
 asked on

HELP! Exchange 2013 shell command to get both a count and then later copy specific emails from a particular user

Shell is new to me and I recently downloaded Power-GUI. I am fairly good with MySQL(SQLYOG user) and MSSQL statements. I am also decent with Winbatch, But so far I am lost with powershell cmdlets. I need to do two things.

 I need to get total count of email in a users mailbox Lets say "John doe@mydomain.com" I need the count of all emails sent to and received from a clients domain such as wildcard@NotMyDomain.com" Something like

getemailcount WHERE mailboxnameis "John Doe" AND WHERE senderis LIKE "notmydomain.com" OR recipientis LIKE "notmydomain.com"

Then once I have the counts confirmed I would like to run a second script that does the same thing  as the first except each result is copied to another mailbox or a public folder.

I am pressed for time so figure I would ask here. Wish we could use the old system and award points as we see fit.
ExchangeEmail SoftwareEmail Servers

Avatar of undefined
Last Comment

8/22/2022 - Mon

Cyprexx IT

Thanks Yo Bee, I guess I should have mention that I had tried the same TechNet article you linked and a couple of  other forums examples, but it does not allow wildcards for the sender or recipient's email address.

I need the PowerSHELL equivalent of the SQL statements:

Select COUNT(*) from "Mail-BOX-NAME" where Sender.Email.Address LIKE "@domain_looking_for.com" or Reciepient.Email.Address LIKE "@domain_looking_for.com"

2nd Shell query:

Select INTO "NEW_MAIL_BOX_FOLDER" * from "Mail-BOX-NAME" where Sender.Email.Address LIKE "@domain_looking_for.com" or Reciepient.Email.Address LIKE "@domain_looking_for.com"

If I could get these into a Powershell or Power GUI I could stop stressing. LOL :)

I do not think you can use the same SQL syntax when querying. Looks like it can be done with KQL http://msdn.microsoft.com/library/ee558911%28v=office.15%29.aspx .

I am only guessing here since I am not even on Exchange 2007 yet.
I do not know the -SearchQuery  fields that can be used, but here is an idea:

Search-Mailbox -Identity "John Doe" -SearchQuery 'From:*@notmydomain.com OR To:*@notmydomain.com'

Open in new window

See if the returns results and if so we can expand on it.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
Cyprexx IT

This is where the problem began, it seems not to like the wild cards in the TO/FROM: . I even tried

Search-Mailbox -Identity "Jamey" -SearchQuery -LIKE 'From:*@fanniemae.com OR -LIKE To:*@fanniemae.com'.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question