I am referencing a list which has a lot of data in the form of the elapsed time of a process and I'm trying to convert it to a format where I can find the average amount of elapsed time.
The data looks something like this:
ElapsedTime
0 hours, 1 minutes, 14 seconds
0 hours, 16 minutes, 2 seconds
0 hours, 4 minutes, 0 seconds
0 hours, 11 minutes, 59 seconds
So I have the above data Imported into a variable and extract the numerical data using this formula:
$ElapsedHours, $ElapsedMinutes, $ElapsedSeconds = $TimeElapsed -split ', ' -split ' ' | Select -Index 0,2,4
From there I assign the values to a variable and an instance of New-TimeSpan:
$ElapsedTimeSpanObject = New-TimeSpan -Hours $ElapsedHours -Minutes $ElapsedMinutes -Seconds -$ElapsedSeconds
This is the part that gets tricky for me. The two above examples of code are all taking place within a Foreach loop and I've already created a blank array. After the timespan object is created, it is inserted into the array and looks at the next ElapsedTime value.
I want to find the average of the total array.
When I execute the current code I have for trying to find the Average I get an error. Here is the code I'm using:
$ElapsedTimespanCollection | Measure-Object -Average
Executing the above code gives me this error for each object in the array:
Measure-Object : Input object "00:02:44" is not numeric. At line:1 char:30 + $ElapsedTimespanCollection | Measure-Object -Average + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidType: (00:02:44:TimeSpan) [Measure-Object], PSInvalidOperationException + FullyQualifiedErrorId : NonNumericInputObject,Microsoft.PowerShell.Commands.MeasureObjectCommand
So how do I go about converting or formatting these measurements of time into something I can check against for their average?