Reputation: 189
I have a list of several thousand custom PS Objects that are exported from another system, and all these custom objects are in a variable $queryResult
. The system exports these objects with a field time
that is in epoch time format in milliseconds (example: 1492536777453 = Tuesday, April 18, 2017 1:32:57 PM) . I need to change all of these time
fields in the custom objects into human readable times. I already have a function that converts epoch time to human readable:
Function Convert-FromUnixDate ($UnixDate) {[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddMilliSeconds($UnixDate))}
I also figured out how to convert all of them, however this just returns a list of times(obviously), and I can't figure out how to update the actual custom objects:
foreach ($i in $queryResult.events.time){$humanReadable = @{};Convert-FromUnixDate $i}
My problem is I want to update the actual value in each PS custom object so that, when I export all the objects to an excel file for the end user, they are readable. Your help is very much appreciated!
EDIT
I forgot to mention what happens when I try to update the values. I tried this statement below:
$aqlQueryResult.events.starttime = Convert-FromUnixDate ($aqlQueryResult.events.starttime)
When I try that, I receive the following error:
Cannot convert argument "value", with value: "System.Object[]", for
"AddMilliseconds" to type "System.Double": "Cannot convert the
"System.Object[]" value of type "System.Object[]" to type "System.Double"."
I understand that I'm receiving this error because my conversion function expects a double, but how can I either change this to expect the correct data type, or find another way to do this?
Upvotes: 1
Views: 617
Reputation: 189
So with a bit of help from @FrodeF and @sodawillow, I have figured out how to update the values inside the actual objects! Below is the line I needed to add.
$queryResult.events | ForEach-Object {$_.time = (Convert-FromUnixDate ($_.time))}
Upvotes: 1