编辑:错误是由使用反斜杠而不是反引号引起的。
提供了ps1文件和一个小样本(tsv)数据文件。我已经完成了解析float / double / decimal类型的各种示例,但由于某种原因,PowerShell似乎在某个数字计数之上失败了。有办法解决这个问题吗?
脚本:
$allData = @()
$sysStats = 0.0, 0.0, 0.0
$count = 0
ForEach($line in Get-Content "SystemStats.tsv")
{
if(-not $line.Contains("PDH"))
{
$line = $line -replace'[""]',""
$entries = $line.split("`t")
$entries[0]
$entries[1]
$entries[2]
$entries[3]
$sysStats[0] = $sysStats[0] + $entries[1]
$sysStats[1] = [decimal] $entries[2]
$sysStats[2] = [float] $entries[3]
[float]$entries[1]
[double]$entries[2]
[decimal]$entries[3]
$count = $count + 1
}
}
$sysStats[0] = $sysStats[0] / $count
$sysStats[1] = $sysStats[1] / $count
$sysStats[2] = $sysStats[2] / $count
$count
$sysStats[0]
$sysStats[1]
$sysStats[2]
数据文件:
"(PDH-TSV 4.0) (E. Australia Standard Time)(-600)" "\\VAWSHRADDEV4001\Processor Information(_Total)\% Processor Time" "\\VAWSHRADDEV4001\Memory\% Committed Bytes In Use" "\\VAWSHRADDEV4001\Network Interface(AWS PV Network Device _0)\Bytes Total/sec"
"12/05/2016 13:02:43.962" " " "24.549028983000845" " "
"12/05/2016 13:02:53.976" "11.686062679123754" "24.678379230714455" "7363.3148341056431"
输出:
12/05/2016 13:02:43.962 24.549028983000845
0
0
0
12/05/2016 13:02:53.976 11.686062679123754 24.678379230714455 7363.3148341056431
0
0
0
2
0
0
0