【发布时间】:2020-06-18 11:47:33
【问题描述】:
我需要将总时间跨度值的结果导出到 csv 文件。
$outItems = New-Object System.Collections.Generic.List[System.Object]
[TimeSpan[]]$outItems = foreach ($eachtimer in $DurationColl){
if ($eachtimer -match 'H|M|S'){
Convert-TimeString -Time $eachtimer -Format 'm\Ms\.fff\S' }
else {
Convert-TimeString -Time $eachtimer -Format "h\:mm\:ss"}
}
$seconds = ($outItems | Measure-Object -Property TotalMilliseconds -Sum).Sum
$ts = [timespan]::FromMilliseconds($seconds)
$ert = ("{0:hh\:mm\:ss\,fff}" -f $ts)
$ert | Export-Csv C:\Users\User\Documents\output.csv -Append -NoTypeInformation -Encoding ASCII
$ert 值为 04:05:38,631,在 csv 上显示属性长度。 在简历中,我的 Export-Csv 不起作用。
感谢您的帮助
【问题讨论】:
-
Export-CSV将输入对象的属性转换为列,并将它们的值转换为行。当您只提供一个字符串时,字符串的唯一属性是Length。你可以做[pscustomobject]@{Time = $ert} | export-csv ...
标签: powershell