REMOTE Powershell for Exchange Invoke-Command

I will be connecting to Exchange via powershell remoting  because i read the searches are alot faster. Once I connect I want to run the following commands:

$msgs = Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -Start "2/07/2018 00:00:00" -End "3/07/2018 23:59:59"} | where{$_.sender -like "*@externaldomain.com"}
$msgs.count

This will give me the message count for all emails that came into the org from a specific external domain.  Since i will be running this from remote powershell instead of the exchange management shell it seems that i need to run the "invoke-command" cmdlet. How should I run that cmdlet with the cmdlets above, or is it even needed. The get-transportserver will get all the transport servers in the org which is about 8 and it includes exchange 2010 and 2016 servers. Let me know if the invoke-command is needed for increased search speed or just remote powershell alone is enough to increase the speed. I have been looking at the article:
https://practical365.com/exchange-server/speed-up-multi-server-message-tracking-log-searches-with-powershell-remoting/

any assistance will be great.
LVL 14
timgreen7077Exchange EngineerAsked:
Who is Participating?
 
timgreen7077Connect With a Mentor Exchange EngineerAuthor Commented:
I got this now resolved. To invoke the command syntax is as follows:

$msgs = Get-TransportServer | Invoke-Command {Get-MessageTrackingLog -ResultSize Unlimited -Start "2/07/2018 12:00:00 AM" -End "3/07/2018 11:59:00 PM" -EventID "DELIVER" | where{$_.sender -like "*@externaldomain.com"}}

The search is really fast also. Notice the location of the brackets, and allowed the cmdlets to work correctly.
0
 
timgreen7077Exchange EngineerAuthor Commented:
See solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.