【发布时间】:2016-03-09 11:34:13
【问题描述】:
我是 Powershell 脚本的新手,我想找到结果变量中数字的标准差。
以下是我的代码:
param(
## The command to measure
[Scriptblock] $Scriptblock,
## The number of times to measure the command's performance
[int] $Iterations = 2
)
Set-StrictMode -Version Latest
## Figure out how many extra iterations we need to account for the outliers
$buffer = [int] ($iterations * 0.1)
$totalIterations = $iterations + (2 * $buffer)
## Get the results
$results = 1..$totalIterations |
Foreach-Object { Measure-Command $scriptblock }
## Sort the results, and skip the outliers
$middleResults = $results | Sort TotalMilliseconds |
Select -Skip $buffer -First $iterations
$popdev = 0
## Show the average
$avg = $results | Measure-Object -Average | select Count, Average
$middleResults | Measure-Object -Average TotalMilliseconds
foreach ($number in $results){
$popdev += [math]::pow(($number - $avg.Average), 2)
}
我收到以下错误:
计数:2 平均:351.1846 总和: 最大 : 最低限度 : 属性:TotalMilliseconds
无法将参数“1”,值为:“”,将“op_Subtraction”转换为类型“System.TimeSpan”:“无法将 null 转换为 键入“System.TimeSpan”。” 在 C:\script.ps1:55 char:3 + $popdev += [数学]::pow(($number - $avg.Average), 2) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
【问题讨论】:
标签: powershell