I have an object with a column I need to convert from Unix time to a "human" time. My object looks like this:
PS C:\Windows\system32\WindowsPowerShell\v1.0> $AllAgents.agents[0..2] | Format-Table
last_scanned ip distro platform name uuid id
------------ -- ------ -------- ---- ---- --
1460167223 192.168.118.101 win-x86-64 WINDOWS COMPUTER-1 648f8f4f-8afa-029d-424f-fb27a8e345f8e2fdef184343058e 101
1460167223 192.168.118.145 win-x86-64 WINDOWS COMPUTER-2 0a33a831-fa47-1fdc-2c21-2a079c728a88bcf6186e275a9135 152
1460167223 192.168.118.26 win-x86-64 WINDOWS COMPUTER-3 738c0d3a-d2d5-447c-c671-b248180c3b3f75efb734be3d547d 359
The "last_scanned" column is what I need to change. I have the following code:
$Origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0
$AllAgents.agents.last_scanned = $AllAgents.agents.last_scanned | ForEach-Object {
$_ = $Origin.AddSeconds($_)
$_
}
Executing this loop results in the following error:
The property 'last_scanned' cannot be found on this object. Verify that the property exists and can be set.
At U:\Powershell\Scripts\Nessus API - Get All Agents From a Group.ps1:55 char:1
+ $AllAgents.agents.last_scanned = $AllAgents.agents.last_scanned | For ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
I'm not sure why PowerShell thinks the last_scanned property doesn't exist because it's clearly there. How can I modify the last_scanned property to a more readable date and put that value back into the object?