PowerShell script exchange
Post Reply
pirx
Veteran
Posts: 658
Liked: 98 times
Joined: Dec 20, 2015 6:24 pm
Contact:

find non existing VMs in excludes and collect VM and Disk excludes in a useful manner

Post by pirx »

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.
david.domask
Veeam Software
Posts: 3065
Liked: 710 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: find non existing VMs in excludes and collect VM and Disk excludes in a useful manner

Post by david.domask »

Hi pirx,

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:

Code: Select all

$allVmIds = Find-VBRViEntity | Where-Object{$_.Type -eq "Vm"} | Select -Property Reference
$backupJob = Get-VBRJob -Name "dd-ps-exclude-test"
$jObjects = Get-VBRJobObject -Job $backupJob | Where-Object {$_.Type -eq "Exclude"}
$jObjects | Where-Object {$_.Object.Reference -notin $allVmIds}

Name                      Type       ApproxSize       Location
----                      ----       ----------       --------
dd-fake-exa-deb           Exclude    0 B             some-vcenter.justadomain.win

Remove-VBRJobObject -Objects $jObjects -Completely
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests