PowerShell script exchange
Post Reply
maanlicht
Enthusiast
Posts: 26
Liked: 5 times
Joined: Apr 05, 2023 1:06 pm
Full Name: maanlicht
Contact:

How to list and remove Orphaned replicas

Post by maanlicht »

Recently I successfully used a script to remove a list of VMs from a set of replication jobs because I believe the instant VM recovery feature is so fast that having a replica is no longer justified for some VMs. (Way the go Veeam!) The replicas however still show up under the ‘Replicas’ section.

I understand the ‘Remove-VBRReplica -FromDisk’ command can be used to clean them up. However the documentation tells me to use the ‘Get-VBRReplica’ command to make the initial selection of VMs. This is where I run into trouble. ‘Get-VBRReplica’ doesn’t seem to return the VM replicas as the documentation states. But instead returns the jobs they once belonged to. This makes it seemingly impossible for me to select the VMs I removed before since the job still exists and I don’t want to remove ALL replicas.

Since this is such a common function, my question to the community is: How do you guys list and remove Orphaned replicas with powershell?
jorgedlcruz
Veeam Software
Posts: 1372
Liked: 619 times
Joined: Jul 17, 2015 6:54 pm
Full Name: Jorge de la Cruz
Contact:

Re: How to list and remove Orphaned replicas

Post by jorgedlcruz »

Unfortunately, there's no direct way to get a list of orphaned VMs using Get-VBRReplica cmdlet, since it returns the list of replica jobs and not the individual VM replicas.

I have tried a few cmdlets and some commands, but nothing drove me far.

Will wait for others that maybe have achieved this with a bit of extra scipting.
Jorge de la Cruz
Senior Product Manager | Veeam ONE @ Veeam Software

@jorgedlcruz
https://www.jorgedelacruz.es / https://jorgedelacruz.uk
vExpert 2014-2024 / InfluxAce / Grafana Champion
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to list and remove Orphaned replicas

Post by oleg.feoktistov » 1 person likes this post

Hi,
‘Get-VBRReplica’ doesn’t seem to return the VM replicas as the documentation states. But instead returns the jobs they once belonged to.
That's not the case, Get-VBRReplica still returns replicas, not the jobs. The difference being is that in the UI we present replicas by VM names, whereas in powershell we present them by job names (true for VMware and Hyper-V replicas, vCD replicas are still presented by VM names). It happens because VMware and Hyper-V replicas don't have their own type in PS and are presented as CBackup. Hence, the schema for CBackup gets applied to these replica types as well. To see that these are, in fact, replicas, you can double check it through DB Manager classes:

Code: Select all

$replica = Get-VBRReplica
[Veeam.Backup.DBManager.CDBManager]::Instance.Replicas.GetReplicasFromBackup($replica[0].Id)
Orphaned replicas are the ones that have JobId property nulled. I'd also filter them by IsImported: $false since we are working with CBackup types here even though replicas cannot really be imported in a sense backups can be:

Code: Select all

$orphanedReplicas = Get-VBRReplica | where {$_.IsImported -eq $false -and $_.JobId -eq '00000000-0000-0000-0000-000000000000'}
$orphanedReplicas
Let me know if the output for the code I provided corresponds to your list of orphaned replicas.

Best regards,
Oleg
maanlicht
Enthusiast
Posts: 26
Liked: 5 times
Joined: Apr 05, 2023 1:06 pm
Full Name: maanlicht
Contact:

Re: How to list and remove Orphaned replicas

Post by maanlicht »

@oleg.feoktistov thankyou that is very helpful information and good to know about the DB Manager classes.
I tested nulled JobId trick in my lab but unfortunately it does not show orphaned VMs if the original job still exists and is in use. However after removing the job it indeed lists ALL the VMs as orphaned replicas. So it looks like the JobId only changes for an orphan if the parent job gets removed.
Do you know of any other way?
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests