Just my input, you're doing tons of extra processing you don't need to in your script.
Code: Select all
$jobBackup.GetObjectOibsAll() | ForEach-Object {
$device = $_
$deviceName=$_.Name
write-log "Fetching dbs for device $($device.Name)"
write-log "Fetching restore point [$($device.Name)]"
$rp = Get-VBRRestorePoint -Backup $jobBackup -Name $device.Name |Sort-Object -Descending CreationTime | Select-Object -First 1
if($rp -ne $null -and (Get-VBRApplicationRestorePoint -Id $rp.Id) -ne $null) {
Basically all of this can be removed and you can just parse on the RestorePoint object property
HasSQL.
Code: Select all
PS C:\Users\Administrator\Desktop> $rp = Get-VBRRestorePoint -Backup $backup |sort -Property CreationTime -Descending
PS C:\Users\Administrator\Desktop> $rp.Hassql
False
True
True
This is a much better way of checking if a restore point should be passed to the Start-VESQLRestore session and it will reduce clutter in your code significantly.
I can't get your code to reproduce the issue in my lab environments, so my guess is you're somehow passing an object that breaks your validation and sends some invalid item, but it's not possible to tell with just the code you have.
Add in some debug lines before starting the VESQL session to post the object name, id, and maybe the object itself to console.