I have an array I would like to display formatted. I have the start and end time in ticks to do some grouping and get a min/max (you can't do min/max with Measure on a datetime format). The issue is I want to display the final output as a datetime, not ticks. I searched and have this code, but can't get it to work. I get an error "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in the correct sequence"
$OpenArr | Group-Object Name | %{
New-Object psobject -Property @{
Item = $_.Name
Sum = ($_.Group | Measure-Object TotalSeconds -Sum)
StartTime = ($_.Group | Measure-Object StartTime -MIN)
EndTime = ($_.Group | Measure-Object EndTime -MAX)
}
}
#$OpenArr
$c1 = @{Expression={$_.Name}}
$c2 = @{Expression={$_.StartTime.ToString("yyyyMMdd")};Label="Start"}
$OpenArr | Sort-Object Name | Format-Table $c1,$c2,TotalSeconds
I also tried just casting the StartTime as a datetime. In playing with it, that isn't even the problem. When I just do Format-table $c1, it gives an error too.
Format-Table. You're not changing$OpenArr. Just keep it all in one pipeline$OpenArr | Group-Object Name | % {New-Object psobject ...} | Sort-Object Item | Format-Table Item,StartTime,EndTime. Not sure how you want to display DateTime from ticks? Like this,[datetime]1000000000 - [datetime]0?$c2 = @{Expression={$_.StartTime.ToString("yyyyMMdd")};Label="Start"}the "$_.StartTime" is in ticks?