1

I'm trying to pull out information about the last Windows restore point made.

So far I've made this

$rpDate = Get-ComputerRestorePoint | Select-Object -Property CreationTime
$rpDesc = Get-ComputerRestorePoint | Select-Object -Property Description

$rpDate[-1]
$rpDesc[-1]

The result is "20180711124151.733659-000", which is date and time, in what I presume is unix time. Normally, in PHP I would make a function($rpDate), but since this is powershell, I am a bit lost.

How do I convert unix time to a real date + timestamp?

SneakyFrog
  • 11
  • 1

1 Answers1

3

You could follow the original instructions from Get-ComputerRestorePoint and format the Date in the original call like this:

Get-ComputerRestorePoint | Format-Table @{Label="Date" ; Expression={$_.ConvertToDateTime($_.CreationTime)}}

The Output should look like this:

Date
----
05.07.2018 08:09:18
05.07.2018 08:11:59
11.07.2018 07:57:54

If you want to get certain elements (like the last entry) you can use Select-Object instead (thx @Jacob), if you also want the Description do it like this:

Get-ComputerRestorePoint | Select @{Label="Date" ; Expression={$_.ConvertToDateTime($_.CreationTime)}}, Description -last 1

You can choose either the Description or the Date by doing (<command>).Date or by using Select-Object -ExpandProperty Date in a Pipe.

If you want to directly convert the time, you have to split the output at the . and follow the instructions here Convert Unix Time with Powershell

Paxz
  • 2,959
  • 1
  • 20
  • 34
  • Thank you. Yes, this works. But I am unable to select the last date in the array and I would like it to also take the description. I'm aiming to get a popupbox, that write the last restore point. If the last restorepoint is older than 7 days, it should warn the user. – SneakyFrog Jul 12 '18 at 09:39
  • Try using select rather than format-table: `Get-ComputerRestorePoint | Select @{Label="Date" ; Expression=$_.ConvertToDateTime($_.CreationTime)}} -last 1` – Jacob Jul 12 '18 at 10:48
  • @SneakyFrog I edited the answer to fit your needs. Thx Jacob for the addition. – Paxz Jul 12 '18 at 10:56