Reputation: 75
How would one convert a PowerShell command output that retrieves some date/time like to a readable date/time string? The command is
((Get-ComputerRestorePoint)[-1]).CreationTime
Which basically retrieves the last restore point created date and time, but in a weird format like 20190109100614.556883-000
Upvotes: 0
Views: 1434
Reputation: 7479
the reason your previous try failed is that you went at it logically instead of doing it the WMI timestamp way. [grin] this works ...
#requires -RunAsAdministrator
$RPCreationTime = (Get-ComputerRestorePoint)[-1]
$RPCreationTime = $RPCreationTime.ConvertToDateTime($RPCreationTime.CreationTime)
# the Out-Host is needed to avoid the display system trying to combine the two items
$RPCreationTime.GetType() | Out-Host
$RPCreationTime
output ...
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True DateTime System.ValueType
2019 January 09, Wednesday 3:00:13 AM
Upvotes: 2
Reputation: 24071
The conversion can be done via RestorePoint object. Like so,
$rp=((Get-ComputerRestorePoint)[-1])
$rp.ConvertToDateTime($rp.CreationTime).ToString("u")
# Result
2019-01-08 08:24:24Z
The u
format is universal sortable sepcifier, there are quite a few alternatives too.
Upvotes: 2