{
"logs": [
{
"timestamp": "20181216T14:36:12",
"description": "IP connectivity via interface ipmp1 has become degraded.",
"type": "alert",
"uuid": "1234567",
"severity": "Minor"
},
{
"timestamp": "20181216T14:38:16",
"description": "Network connectivity via port ibp4 has been established.",
"type": "alert",
"uuid": "12345678",
"severity": "Minor"
}
]
}
I have this JSON object, and I want to iterate through each object and update the timestamp to a more readable date. Right now, I have
$currentLogs.logs |
Where{$_.type -eq 'alert'} |
ForEach{$_.timestamp = {[datetime]::parseexact($_.timestamp, 'yyyyMMdd\THH:mm:ss', $null)}}
But when I read the object $currentLogs, it still hasn't updated.
$_.timestamp
to a script block and never executed the script block. Plus you have only attempted to parse the value and not supplied a new format after parsing unless you want the default format to be applied to your value's data type. – AdminOfThings{ }
braces after=
surrounding theparseexact()
command in yourForEach{$_.timestamp = {[datetime]::parseexact(...
line – Daniel