2012-06-20 54 views
0

我需要測量腳本塊(遠程執行)花費的時間。使用Powershell測量調用命令

這是我的代碼:

try 
{ 

    Invoke-Command -credential $testCred -computer $ServerName -scriptblock { 
     param([String]$scriptDeploy, [String]$destino) &"$scriptDeploy" 'parametro1' $destino 
     $ScriptBlockOutput = $Error 
    } -ArgumentList $RutaRemotaParaScriptDeInstalacion, "$dirRemotoDestino" 

    "`r`n`r`nOK para script de despliegue" 
    exit 0; 

} 
catch 
{ 
    "`r`n`r`nError en script de despliegue" 
    "`r`nError in " + $_.InvocationInfo.ScriptName + " at line: " + $_.InvocationInfo.ScriptLineNumber + ", offset: " + $_.InvocationInfo.OffsetInLine + "."; 

    exit -1 
} 

我想是這樣的:
http://powershell.com/cs/blogs/tips/archive/2012/06/19/check-powershell-speed.aspx

$timespan = Measure-Command $code 
"Your code took {0:0.000} seconds to run" -f $timespan.TotalSeconds 

它有什麼建議?

UPDATE:我的解決方案

$timespan = Measure-Command -Expression { 

     Invoke-Command -credential $testCred -computer $ServerName -scriptblock { 
      param([String]$scriptDeploy, [String]$destino) &"$scriptDeploy" 'parametro1' $destino 
      $ScriptBlockOutput = $Error 
     } -ArgumentList $RutaRemotaParaScriptDeInstalacion, "$dirRemotoDestino" 

    } 

"`r`n`r`nScript ha tardado {0:0.000} segundos en ejectuarse" -f $timespan.TotalSeconds 
+0

http://powershell.com/cs/blogs/tips/archive/2012/06/19/check-powershell-speed.aspx –

回答

0

問題是什麼? Everthing你寫的很好。

$timespan = Measure-Command -Expression { <your code here> } 

問候