我有下面的代碼,這是爲了總計時間偏移隨着循環旋轉(我將然後需要除以10獲得平均值,但首先我需要得到這個位工作)。Powershell在循環中添加數字
我假設我需要將某些內容轉換爲[INT],但我嘗試了多個位置,但無濟於事。我只是以O而告終。
$winTimeStripchart = w32tm /stripchart /computer:0.pool.ntp.org /dataonly /samples:10
$WinTimeOffset = $null
For($i=3; $i -le 12; $i++){
$Offset = $winTimeStripchart[$i].split("-")
$trimmedOffset = $Offset[1].trim("s")
$winTimeOffset = $winTimeOffset + $trimmedOffset
}
Write-Host "Total: $winTimeOffset"
# Now need to divide by 10.
樣本數據:
20:30:23, -00.0698082s
20:30:25, -00.0704645s
20:30:27, -00.0708694s
20:30:29, -00.0728990s
20:30:31, -00.0719226s
20:30:33, -00.0749031s
20:30:36, -00.0778656s
20:30:38, -00.0782183s
20:30:40, -00.0752974s
20:30:42, -00.0760958s
如果您向我們展示了一些示例數據,我們可以幫助更輕鬆。 –
當然,上面加了。 Thnaks – PnP
好的,你想要的。如果有機會數字可能是積極的話,請將它分開。您不希望將整數轉換爲整數,因爲它將使所有示例值爲零,而小數可能是最好的類型:[PowerShell Data Types](http://ss64.com/ps/syntax- datatypes.html)。 –