We searched online and it resulted in only getting values to be stored in hash table row wise which does not help at all in this case. Please see attached csv for real data that we will be using.
Thanks in advance for the help
Just to be clear, each row has the same number of columns, correct? I’d probably use a combination of Import-Csv and Measure-Object for this. For example:
$data = Import-Csv -Path .\Log9192014153241.csv
# We skip the first column that contains date / time, because it doesn't make sense to average that.
$properties = $data |
Get-Member -MemberType NoteProperty |
Select-Object -Skip 1 -ExpandProperty Name
$averages = @{}
foreach ($property in $properties)
{
# I see in your sample that you may have some rows that don't contain numeric data. Those
# will cause Measure-Object -Average to fail, so we filter those out with Where-Object first.
$stats = $data |
Where-Object { $null -ne ($_.$property -as [double]) } |
Measure-Object -Average -Property $property
$averages[$property] = $stats.Average
}
This builds a hashtable which maps column names to average values, and you can output that however you like.
Thanks for you reply. Yes each row has fixed columns and also the first column is always date so we would have to exclude it.
I will try this and let you know.