We were great in adding excluded in the past 10 years. Problem is that an excluded keeps existing even if the source VM was removed long ago. The VM or it's excluded disks are still shown and returned in powershell queries. I've 2 scripts that are based on...
Get-VBRJobObject -Job $Job | Where Type -eq "ExcludeDisksChild")
Get-VBRJobObject -Job $job | Where Role -eq "EExclude"))
...is there an easy way to also find VMs in excludes that do not exist anymore in vSphere? That would be #1 excluded that I would remove, ideally automatically in the same script.
If someone has a nice script that already helps to find and cleanup excludes, I'd be very much interested.
I don't have a ready-made script handy, but I suppose the easiest way is a combination of Get-VBRJobObject and Find-VBRViEntity (or Find-VBRHvEntity for HyperV)
Objects returned by Get-VBRJobObject have an Object property, and the Object property has a Reference property that will align with the actual MoRef ID / VM GUID from production.
I think easiest way is just make an array of all the VM references at the start of the clean-up script, then compare with -notin to find jobs with objects that no longer exist in production and pass those to Remove-VBRJobObject with the -Completely parameter. Very simple example: