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,