0

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

3
  • Possible duplicate of stackoverflow.com/questions/38717490/… Commented Jan 10, 2019 at 8:14
  • that cmdlet appears to be a really simple wrapper around a WMI call. so you can use the usual fix for those datetime strings ... .ConvertToDateTime(). Commented Jan 10, 2019 at 8:25
  • tried that on my multiple trial and error. no go. ((Get-ComputerRestorePoint)[-1]).CreationTime.ConvertToDateTime() Method invocation failed because [System.String] does not contain a method named 'ConvertToDateTime'. Commented Jan 10, 2019 at 8:28

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.