PowerShell script exchange
Post Reply
Petr_R
Novice
Posts: 3
Liked: never
Joined: Apr 21, 2024 8:22 am
Full Name: Petr Rihak
Contact:

Powershell command to collect the last restore point with date/time of creation.

Post by Petr_R »

Hello community,
new in PS and I try to search the forum but no luck :( If you can advise me...
My point is to get a list of last backup (restore point) for all VMs with date/time of creation that are visible under Backups
Something like:

VM Date Time Type
xx 09.10.2024 23:50 Incremental
yy 05.09.2024 22:15 Full
zz 28.02.2023 20:45 Full

etc.. that i will be able to sort it out from the oldest to the actual.

Thank you.
david.domask
Veeam Software
Posts: 2575
Liked: 603 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Powershell command to collect the last restore point with date/time of creation.

Post by david.domask »

Hi Petr, welcome to the forums.

Sure, this is a pretty fast one. Get the backup with Get-VBRBackup, then pass it to Get-VBRRestorePoint on the -Backup parameter, then you can filter the output by piping it to Sort-Object (sort for short in the below):

Code: Select all

$backup = Get-VBRBackup -Name "BJ-Nano"
$rPoints = Get-VBRRestorePoint -Backup $backup
$rPoints | Sort -Property CreationTime

VM Name                   Creation Time          Type
-------                   -------------          ----
HK-Nano                   05.10.2023 10:42:20    Full
HK-Nano                   05.10.2023 10:57:47    Full
HK-Nano                   05.10.2023 10:59:44    Full
nano-nimble               05.10.2024 14:55:58    Rollback
nano-nimble               06.10.2024 14:55:51    Rollback
nano-nimble               07.10.2024 14:55:48    Rollback
nano-nimble               08.10.2024 14:55:39    Full
You can check the additional properties you might want in your report by simply checking one of the objects in $rPoints with Get-Member:

$rPoints[0] | Get-Member #Get-Member can be shortened to gm
David Domask | Product Management: Principal Analyst
Petr_R
Novice
Posts: 3
Liked: never
Joined: Apr 21, 2024 8:22 am
Full Name: Petr Rihak
Contact:

Re: Powershell command to collect the last restore point with date/time of creation.

Post by Petr_R »

Hello,
thanks for a fast reply...the point is that I dont need to see all restore points (backups) per each VM but just the latest...as bellow HK-nano1,2, etc are independent separate VMs...
Something like :

VM Name Creation Time Type
------- ------------- ----
HK-Nano1 05.10.2023 10:42:20 Full
HK-Nano2 05.10.2023 10:57:47 Full
HK-Nano3 05.10.2023 10:59:44 Full
nano-nimble1 05.10.2024 14:55:58 Rollback
nano-nimble2 06.10.2024 14:55:51 Rollback
nano-nimble3 07.10.2024 14:55:48 Rollback
nano-nimble4 08.10.2024 14:55:39 Full
Petr_R
Novice
Posts: 3
Liked: never
Joined: Apr 21, 2024 8:22 am
Full Name: Petr Rihak
Contact:

Re: Powershell command to collect the last restore point with date/time of creation.

Post by Petr_R »

and second point is that I have on one site 34 jobs with a lot a VMs inside, so specify it to one job and rewrite it in script is quite time consuming :D
david.domask
Veeam Software
Posts: 2575
Liked: 603 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Powershell command to collect the last restore point with date/time of creation.

Post by david.domask »

Hi Petr,

Ah, so you just need the last point only? Maybe can you show a sample output of what you are seeking?

The same code can be used, but instead you will do a little filtering on the ObjectID of the objects under $rPoints.

Code: Select all

$backup = Get-VBRBackup -Name "BJ-Nano"
$rPoints = Get-VBRRestorePoint -Backup $backup
$objIds = $rPoints.ObjectId | Sort -Unique
$latestRP = @()
Foreach($id in $objIds){
     $vmRps = $rPoints | Where-Object {$_.ObjectID -eq $id} | Sort -Property CreationTime -Descending | Select -First 1
     $latestRP += $vmRps
}
$latestRP
This will print just the most recent restore point. I wanted to show you how to do it just for a job at first to see the workflow, but as you can see, it's best to fetch the restore points by first fetching the backups with Get-VBRBackup. Thus, a more complete script can look like:

Code: Select all

$backups = Get-VBRBackup
$latestRP = @()
ForEach($b in $backups){
     $rPoints = Get-VBRRestorePoint -Backup $b
     $objIds = $rPoints.ObjectId | Sort -Unique
     Foreach($id in $objIds){
          $vmRps = $rPoints | Where-Object {$_.ObjectID -eq $id} | Sort -Property CreationTime -Descending | Select -First 1
          $latestRP += $vmRps
	}
}

$latestRP
If you're in a smaller environment, you can even just skip a bit and collect all the restore points with:

Code: Select all

$latestRP = @()
$rPoints = Get-VBRRestorePoint
$objIds = $rPoints.ObjectId | Sort -Unique
     Foreach($id in $objIds){
          $vmRps = $rPoints | Where-Object {$_.ObjectID -eq $id} | Sort -Property CreationTime -Descending | Select -First 1
          $latestRP += $vmRps
}
Just keep in mind Get-VBRRestorePoints without any parameters will return _all restore points_, and this can sometimes cause execution to take awhile, and if you decide to expand your script and report on more items, you may want some data off the CBackup objects returned by Get-VBRBackup,
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 48 guests