首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Measure Invoke-使用Powershell的命令

Measure Invoke-使用Powershell的命令
EN

Stack Overflow用户
提问于 2012-06-20 14:19:30
回答 1查看 924关注 0票数 0

我需要测量一下scriptblock (远程执行)所用的时间。

这是我的代码:

代码语言:javascript
复制
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

代码语言:javascript
复制
 $timespan = Measure-Command $code
 "Your code took {0:0.000} seconds to run" -f $timespan.TotalSeconds

对此有什么建议吗?

更新:我的解决方案

代码语言:javascript
复制
    $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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-20 14:59:46

有什么问题吗?你写的一切都很好。

代码语言:javascript
复制
$timespan = Measure-Command -Expression { <your code here> }

诚挚的问候

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11113844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档