Hi Mike,
Check out these links for more resources on the TimeAgo function:
But, I get the impression that you want total control of the formatting of the DateTime value?
If you do, then you need to format the value as a String in your script.
Here is an example script that shoots out the LastBootUpTime value in three different ways.
Get-WmiObject Win32_OperatingSystem |
Select csname, LastBootUpTime,
@{LABEL = 'LastBootUpTime2'; EXPRESSION = { $_.ConverttoDateTime($_.lastbootuptime) } },
@{LABEL = 'LastBootUpTime3'; EXPRESSION = { ('{0:yyyy}/{0:MM}/{0:dd} {00:hh}:{00:mm}:{00:ss} {0:tt}' -f $_.ConverttoDateTime($_.lastbootuptime)).ToString()}}
If you want the long-winded explanation, that begins here.
On a SquaredUp Dashboard, the first value will appear as:
20210831140614.094750-240
When you apply the TimeAgo function in the Grid Column, it will then appear as:
August 31st 2021, 12:00:00 am
Take note that the time value is 12:00:00 am. I have found that when working with WMI, the DateTime value is returned in a weird format. In order to get the time portion of the value, you need to reformat the value like this:
$_.ConverttoDateTime($_.lastbootuptime)
This will output:
1630418774094.75
And when you apply the TimeAgo function, you will get:
August 31st 2021, 10:06:14 am
But if you want to format the value in a specific way, I don’t think the TimeAgo function will do that. But if you format the value as a String before it’s sent to SquaredUp, you can format it in any way that you want. Here’s an example:
('{0:yyyy}/{0:MM}/{0:dd} {00:hh}:{00:mm}:{00:ss} {0:tt}' -f $_.ConverttoDateTime($_.lastbootuptime)).ToString()
This will output:
2021/08/31 10:06:14 PM
Be warned, I didn’t account for any time zone drama. So, if your value is off by a couple of hours, you will need to adjust for the timezone in whatever way makes sense for you.
Hopefully, that helps.