locked
Invoke-command on 5 Exchange servers is not saving me time RRS feed

  • Question

  • Because a command running on 1 computer is taking way too long to finish I would like to create a brand new command that will run simultaneously on all 5 computers. I think the invoke command is perfect for this scenario.

    This is what I would like to accomplish:

    $servers=Get-TransportService | select -ExpandProperty name
    foreach ($server in $servers) { Invoke-Command -ComputerName $server -FilePath .\MessageTrackingLog.ps1 }
    
    
    #MessageTrackinglog.ps1 contains the following
    
    
    Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010
    Get-MessageTrackingLog -Start “09/07/2017 12:00 AM” -End “09/08/2017 12:00 AM” -ResultSize Unlimited |
    Where {$_.MessageLatencyType -eq “EndToEnd” -And $_.MessageLatency -gt “00:02:00”} |
    Select MessageLatency,Sender,MessageId |Sort-Object -Property MessageLatency -Descending | 
    Export-Csv C:\locationtosave\MessageTrackingResults.csv
    
    #Problem is that t is taking the same amount of time.
    
    #Help please
    
    
    
    


    Saturday, September 9, 2017 3:23 PM

Answers

  • To run concurrent commands you must use either a workflow or a set of jobs.  "Invoke-Command" will only run one instance at a time.

    Invoke-Command -ComputerName$servers -FilePath .\MessageTrackingLog.ps1 -AsJob

    help Invoke-Command -Full

    This is the easiest way to run remote commands in parallel.  Without the "AsJob" they will run one at a time.


    \_(ツ)_/

    • Marked as answer by Tiri2014 Sunday, September 10, 2017 3:46 AM
    Saturday, September 9, 2017 5:49 PM

All replies

  • To run concurrent commands you must use either a workflow or a set of jobs.  "Invoke-Command" will only run one instance at a time.

    Invoke-Command -ComputerName$servers -FilePath .\MessageTrackingLog.ps1 -AsJob

    help Invoke-Command -Full

    This is the easiest way to run remote commands in parallel.  Without the "AsJob" they will run one at a time.


    \_(ツ)_/

    • Marked as answer by Tiri2014 Sunday, September 10, 2017 3:46 AM
    Saturday, September 9, 2017 5:49 PM
  • That has nothing to do with your question.  The code you wrote creates the CSV on the remote server.  Where else would you expect a remote command to create a file?


    \_(ツ)_/

    Sunday, September 10, 2017 12:47 AM