Não tenho certeza se o OP foi respondido, então vou enviar o que desenvolvi depois de procurar sem sucesso a mesma resposta.
Eu uso duas abordagens diferentes para isso, para testar as conexões entre os servidores Exchange e o servidor que será designado em um argumento New-MailboxExportRequest -FilePath.
#invoke-command (test-connection)
function Get-TestConnectionResponseTime
{
#returns a hash of min, max, avg ping times
param($Pingee,$Pinger)
$TCScript="
'$result = Test-Connection $Pingee
'$min=('$result|Measure-Object -Minimum -Property responsetime).Minimum
'$max=('$result|Measure-Object -Maximum -Property responsetime).Maximum
'$avg=('$result|Measure-Object -Average -Property responsetime).Average
@{Min='$min;Max='$max;Avg='$avg}
"
$CxtScript = $ExecutionContext.InvokeCommand.NewScriptBlock($TCScript)
try{
Invoke-Command -ComputerName $Pinger -ScriptBlock $CxtScript -ErrorAction Stop}
catch [System.Management.Automation.RuntimeException]{
return "Probably a firewall restriction: " + $error[0].FullyQualifiedErrorId}
catch{
return "From catch-all error trap: " + $error[0].FullyQualifiedErrorId}
}
#start-process (psexec -> ping)
function Get-PingResponseTime
{
#uses start-process to run ping from remote to remote, returns a hash of min, max, avg ping times
# this one is slow and clunky, but psexec is allowed though some of the firewalls I contend with,
# and invoke-command isn't. To collect the output in the script, I had to write it to a log and
# pick it up afterwards (by watching for the last line of the output to appear in the log file)
param($Pingee,$Pinger)
$argumentlist = "$Pinger ping $Pingee"
$timestamp = Get-Date
$psexecID = Start-Process -FilePath psexec -ArgumentList ("\" + $argumentlist) -NoNewWindow -RedirectStandardOutput \MyComputer\c$\temp\pinglog.txt -PassThru #-Wait
Write-Host "Started process" $psexecID.Name
#wait for the remote process to finish
While(Get-Process -ComputerName $Pinger | ?{$_.Name -eq $psexecID.Name}){
Write-Host "." -NoNewline
}
#wait for the completed log file on my local system
Write-Host "Waiting for $pinger to return results..."
while(!((Get-Content C:\temp\pinglog.txt) -match "Average = ")){
Write-Host "." -NoNewline
Start-Sleep -Seconds 1
}
Write-Host " ah, there they are!"
#parse the ping output
$pingtimes = ((Get-Content C:\temp\pinglog.txt) -match "Average = ").trim() -split ", " | %{($_ -split " = ")[1].trim("ms")}
return @{Min=$pingtimes[0];Max=$pingtimes[1];Avg=$pingtimes[2]}
}
Espera que isso ajude alguém.